From d491843640658e91a77f15647cefd1c00422c731 Mon Sep 17 00:00:00 2001
From: Vinayak hariharmath <65405035+VHariharmath-rh@users.noreply.github.com>
Date: Wed, 21 Oct 2020 16:14:29 +0530
Subject: [PATCH 565/584] libglusterfs/coverity: pointer to local outside the
scope
issue: gf_store_read_and_tokenize() returns the address
of the locally referred string.
fix: pass the buf to gf_store_read_and_tokenize() and
use it for tokenize.
CID: 1430143
Backport of:
> Upstream-patch: https://github.com/gluster/glusterfs/pull/1675
> Updates: #1060
> Change-Id: Ifc346540c263f58f4014ba2ba8c1d491c20ac609
> Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>
BUG: 1925425
Change-Id: Ifc346540c263f58f4014ba2ba8c1d491c20ac609
Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/244959
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
libglusterfs/src/glusterfs/store.h | 3 ++-
libglusterfs/src/store.c | 13 ++++++++-----
xlators/mgmt/glusterd/src/glusterd-store.c | 3 ++-
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/libglusterfs/src/glusterfs/store.h b/libglusterfs/src/glusterfs/store.h
index f63bd05..68a20ad 100644
--- a/libglusterfs/src/glusterfs/store.h
+++ b/libglusterfs/src/glusterfs/store.h
@@ -60,7 +60,8 @@ gf_store_unlink_tmppath(gf_store_handle_t *shandle);
int
gf_store_read_and_tokenize(FILE *file, char **iter_key, char **iter_val,
- gf_store_op_errno_t *store_errno);
+ gf_store_op_errno_t *store_errno, char *str,
+ size_t buf_size);
int32_t
gf_store_retrieve_value(gf_store_handle_t *handle, char *key, char **value);
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c
index fa3649b..3af627a 100644
--- a/libglusterfs/src/store.c
+++ b/libglusterfs/src/store.c
@@ -185,7 +185,8 @@ out:
int
gf_store_read_and_tokenize(FILE *file, char **iter_key, char **iter_val,
- gf_store_op_errno_t *store_errno)
+ gf_store_op_errno_t *store_errno, char *str,
+ size_t buf_size)
{
int32_t ret = -1;
char *savetok = NULL;
@@ -193,7 +194,6 @@ gf_store_read_and_tokenize(FILE *file, char **iter_key, char **iter_val,
char *value = NULL;
char *temp = NULL;
size_t str_len = 0;
- char str[8192];
GF_ASSERT(file);
GF_ASSERT(iter_key);
@@ -201,7 +201,7 @@ gf_store_read_and_tokenize(FILE *file, char **iter_key, char **iter_val,
GF_ASSERT(store_errno);
retry:
- temp = fgets(str, 8192, file);
+ temp = fgets(str, buf_size, file);
if (temp == NULL || feof(file)) {
ret = -1;
*store_errno = GD_STORE_EOF;
@@ -275,8 +275,9 @@ gf_store_retrieve_value(gf_store_handle_t *handle, char *key, char **value)
fseek(handle->read, 0, SEEK_SET);
}
do {
+ char buf[8192];
ret = gf_store_read_and_tokenize(handle->read, &iter_key, &iter_val,
- &store_errno);
+ &store_errno, buf, 8192);
if (ret < 0) {
gf_msg_trace("", 0,
"error while reading key '%s': "
@@ -533,6 +534,8 @@ gf_store_iter_get_next(gf_store_iter_t *iter, char **key, char **value,
int32_t ret = -1;
char *iter_key = NULL;
char *iter_val = NULL;
+ char buf[8192];
+
gf_store_op_errno_t store_errno = GD_STORE_SUCCESS;
GF_ASSERT(iter);
@@ -540,7 +543,7 @@ gf_store_iter_get_next(gf_store_iter_t *iter, char **key, char **value,
GF_ASSERT(value);
ret = gf_store_read_and_tokenize(iter->file, &iter_key, &iter_val,
- &store_errno);
+ &store_errno, buf, 8192);
if (ret < 0) {
goto out;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index da63c03..a8651d8 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -4128,8 +4128,9 @@ glusterd_store_retrieve_missed_snaps_list(xlator_t *this)
}
do {
+ char buf[8192];
ret = gf_store_read_and_tokenize(fp, &missed_node_info, &value,
- &store_errno);
+ &store_errno, buf, 8192);
if (ret) {
if (store_errno == GD_STORE_EOF) {
gf_msg_debug(this->name, 0, "EOF for missed_snap_list");
--
1.8.3.1