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