From 741f652769bc074fe85da1485e0e16df6e6766f1 Mon Sep 17 00:00:00 2001 From: Sanju Rakonde Date: Thu, 10 Jan 2019 16:17:39 +0530 Subject: glusterd: fix crash Problem: running "gluster get-state glusterd odir /get-state" resulted in glusterd crash. Cause: In the above command output directory has been specified without "/" at the end. If "/" is not given at the end, "/" will be added to path using "strcat", so the added character "/" is not having memory allocated. When tried to free, glusterd will crash as"/" has no memory allocated. Solution: Instead of concatenating "/" to output directory, add it to output filename. Change-Id: I5dc00a71e46fbef4d07fe99ae23b36fb60dec1c2 fixes: bz#1665038 Signed-off-by: Sanju Rakonde --- xlators/mgmt/glusterd/src/glusterd-handler.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index e18dfaceae2..5d89aa0f46b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -5548,10 +5548,9 @@ glusterd_get_state(rpcsvc_request_t *req, dict_t *dict) gf_asprintf(&filename, "%s", tmp_str); } - if (odir[odirlen - 1] != '/') - strcat(odir, "/"); + ret = gf_asprintf(&ofilepath, "%s%s%s", odir, + ((odir[odirlen - 1] != '/') ? "/" : ""), filename); - ret = gf_asprintf(&ofilepath, "%s%s", odir, filename); if (ret < 0) { GF_FREE(odir); GF_FREE(filename); -- cgit