From 224af5bc6ea27a617f222cd83da871df85c6b7a1 Mon Sep 17 00:00:00 2001
From: Samikshan Bairagya <samikshan@gmail.com>
Date: Thu, 9 Nov 2017 15:15:37 +0530
Subject: [PATCH 182/201] glusterd: Fix coverity issues in glusterd-handler.c
Fixes get-state CLI related coverity issues 477, 511, 515, 523,
526 and 527 from the report at [1]
[1] https://download.gluster.org/pub/gluster/glusterfs/static-analysis/master/glusterfs-coverity/2017-10-30-9aa574a5/html/
>upstream mainline patch : https://review.gluster.org/#/c/18706/
Change-Id: Ieb6f64c9035b4d9338d9515de003d607b7a4e9bc
BUG: 1528733
Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/132080
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
xlators/mgmt/glusterd/src/glusterd-handler.c | 34 ++++++++++++++++++++--------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 81926a8..16a3773 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -5426,6 +5426,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
char *odir = NULL;
char *filename = NULL;
char *ofilepath = NULL;
+ char *tmp_str = NULL;
int count = 0;
int count_bkp = 0;
int odirlen = 0;
@@ -5435,6 +5436,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
uint64_t memtotal = 0;
uint64_t memfree = 0;
int start_index = 0;
+ char id_str[64] = {0,};
char *vol_type_str = NULL;
char *hot_tier_type_str = NULL;
@@ -5453,12 +5455,14 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
GF_VALIDATE_OR_GOTO (this->name, dict, out);
- ret = dict_get_str (dict, "odir", &odir);
+ ret = dict_get_str (dict, "odir", &tmp_str);
if (ret) {
gf_asprintf (&odir, "%s", "/var/run/gluster/");
gf_msg (this->name, GF_LOG_INFO, 0,
GD_MSG_DICT_GET_FAILED,
"Default output directory: %s", odir);
+ } else {
+ gf_asprintf (&odir, "%s", tmp_str);
}
dp = sys_opendir (odir);
@@ -5481,7 +5485,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
goto out;
}
- ret = dict_get_str (dict, "filename", &filename);
+ ret = dict_get_str (dict, "filename", &tmp_str);
if (ret) {
now = time (NULL);
strftime (timestamp, sizeof (timestamp),
@@ -5491,6 +5495,8 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
gf_msg (this->name, GF_LOG_INFO, 0,
GD_MSG_DICT_GET_FAILED,
"Default filename: %s", filename);
+ } else {
+ gf_asprintf (&filename, "%s", tmp_str);
}
odirlen = strlen (odir);
@@ -5509,7 +5515,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
GF_FREE (odir);
GF_FREE (filename);
- ret = dict_set_dynstr (dict, "ofilepath", ofilepath);
+ ret = dict_set_str (dict, "ofilepath", ofilepath);
if (ret) {
gf_msg (this->name, GF_LOG_ERROR, 0,
GD_MSG_DICT_SET_FAILED, "Unable to set output path");
@@ -5564,7 +5570,9 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
fprintf (fp, "[Global]\n");
- fprintf (fp, "MYUUID: %s\n", gf_strdup (uuid_utoa (priv->uuid)));
+ uuid_utoa_r (priv->uuid, id_str);
+ fprintf (fp, "MYUUID: %s\n", id_str);
+
fprintf (fp, "op-version: %d\n", priv->op_version);
fprintf (fp, "\n[Global options]\n");
@@ -5656,8 +5664,10 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
}
fprintf (fp, "Volume%d.name: %s\n", ++count, volinfo->volname);
- fprintf (fp, "Volume%d.id: %s\n", count,
- gf_strdup (uuid_utoa (volinfo->volume_id)));
+
+ uuid_utoa_r (volinfo->volume_id, id_str);
+ fprintf (fp, "Volume%d.id: %s\n", count, id_str);
+
fprintf (fp, "Volume%d.type: %s\n", count, vol_type_str);
fprintf (fp, "Volume%d.transport_type: %s\n", count,
transport_type_str);
@@ -5777,8 +5787,11 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
fprintf (fp, "Volume%d.snapd_svc.inited: %s\n", count,
volinfo->snapd.svc.inited ? "True" : "False");
- fprintf (fp, "Volume%d.rebalance.id: %s\n", count,
- gf_strdup (uuid_utoa (volinfo->rebal.rebalance_id)));
+ uuid_utoa_r (volinfo->rebal.rebalance_id, id_str);
+ char *rebal_data = gf_uint64_2human_readable (
+ volinfo->rebal.rebalance_data);
+
+ fprintf (fp, "Volume%d.rebalance.id: %s\n", count, id_str);
fprintf (fp, "Volume%d.rebalance.status: %s\n", count,
rebal_status_str);
fprintf (fp, "Volume%d.rebalance.failures: %"PRIu64"\n", count,
@@ -5789,11 +5802,12 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
volinfo->rebal.lookedup_files);
fprintf (fp, "Volume%d.rebalance.files: %"PRIu64"\n", count,
volinfo->rebal.rebalance_files);
- fprintf (fp, "Volume%d.rebalance.data: %s\n", count,
- gf_uint64_2human_readable (volinfo->rebal.rebalance_data));
+ fprintf (fp, "Volume%d.rebalance.data: %s\n", count, rebal_data);
fprintf (fp, "Volume%d.time_left: %"PRIu64"\n", count,
volinfo->rebal.time_left);
+ GF_FREE (rebal_data);
+
if (volinfo->type == GF_CLUSTER_TYPE_TIER) {
ret = glusterd_volume_get_hot_tier_type_str (
volinfo, &hot_tier_type_str);
--
1.8.3.1