From ee255e239aaa1ed5f6388c48a8919989535f3dcc Mon Sep 17 00:00:00 2001 From: Jiffin Tony Thottan Date: Mon, 13 Apr 2015 15:23:51 +0530 Subject: features/trash : fixing trash dir option Previously, problem was caused due to buffer overflow of variable used in the code. This patch fix the same. Change-Id: I3df5e06044470022f9475d93d33447db35384da2 BUG: 1132465 Signed-off-by: Jiffin Tony Thottan Reviewed-on: http://review.gluster.org/10215 Tested-by: NetBSD Build System Tested-by: Gluster Build System Reviewed-by: Anoop C S Reviewed-by: Vijay Bellur --- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-op-sm.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index c91fdbcea4f..33df2c31d8a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -667,6 +667,7 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) char *val_dup = NULL; char str[100] = {0, }; char *trash_path = NULL; + int trash_path_len = 0; int count = 0; int dict_count = 0; char errstr[2048] = {0, }; @@ -988,9 +989,14 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) brick_list) { /* Check for local brick */ if (!gf_uuid_compare (brickinfo->uuid, MY_UUID)) { - trash_path = gf_strdup (brickinfo->path); - strcat(trash_path, "/"); - strcat(trash_path, value); + trash_path_len = strlen (value) + + strlen (brickinfo->path) + 2; + trash_path = GF_CALLOC (1, + trash_path_len, + gf_common_mt_char); + snprintf (trash_path, trash_path_len, + "%s/%s", brickinfo->path, + value); /* Checks whether a directory with given option exists or not */ @@ -1021,6 +1027,11 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) goto out; } } + if (trash_path) { + GF_FREE (trash_path); + trash_path = NULL; + trash_path_len = 0; + } } } else if (!strcmp(key, "features.trash-dir") && !trash_enabled) { snprintf (errstr, sizeof (errstr), -- cgit