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