summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamikshan Bairagya <samikshan@gmail.com>2017-11-09 15:15:37 +0530
committerJeff Darcy <jeff@pl.atyp.us>2017-11-15 14:35:51 +0000
commitc46618973a22875bca4ac8835cc71bb8f3aeaa65 (patch)
tree97f68e38cc46711dae3ffd2400dbf3d2e34a2372
parentf65ad580cf81b4853fa496b628f3dfd9d7b66ee9 (diff)
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/ Change-Id: Ieb6f64c9035b4d9338d9515de003d607b7a4e9bc BUG: 789278 Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 48f216b4a67..ca4a60797a1 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -5363,6 +5363,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;
@@ -5372,6 +5373,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;
@@ -5390,12 +5392,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);
@@ -5418,7 +5422,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),
@@ -5428,6 +5432,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);
@@ -5436,6 +5442,9 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
gf_asprintf (&ofilepath, "%s%s", odir, filename);
+ GF_FREE (odir);
+ GF_FREE (filename);
+
ret = dict_set_str (dict, "ofilepath", ofilepath);
if (ret) {
gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -5491,7 +5500,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");
@@ -5583,8 +5594,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);
@@ -5702,8 +5715,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,
@@ -5714,11 +5730,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);