From 5c1ce6d29ee52af9daa23c1c7a54f23ce29a687e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 31 Mar 2015 10:30:22 +0200 Subject: features/trash: fix remove_trash_path() to do what it is intended. The intention is to set the the rem_path string pointer that is handed in from the outside. So the string has to be passed in by reference, or else the function just sets a pointer on the stack. Found by Coverity, CID 1288791 Also fixes: CID 1288791 CID 1288809 CID 1288810 CID 1288814 CID 1288815 CID 1288817 CUD 1288818 Change-Id: I6ef5eeb58b83a875cf90513291abe37dee3fc9fb BUG: 789278 Signed-off-by: Michael Adam Reviewed-on: http://review.gluster.org/10064 Tested-by: Gluster Build System Reviewed-by: Anoop C S Reviewed-by: Vijay Bellur --- xlators/features/trash/src/trash.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c index fb9ca9a0ee5..c1d78602c4c 100644 --- a/xlators/features/trash/src/trash.c +++ b/xlators/features/trash/src/trash.c @@ -118,12 +118,15 @@ copy_trash_path (const char *priv_value, gf_boolean_t internal, char *path) * similar to orginal path. */ void -remove_trash_path (const char *path, gf_boolean_t internal, char *rem_path) +remove_trash_path (const char *path, gf_boolean_t internal, char **rem_path) { + if (rem_path == NULL) { + return; + } - rem_path = strchr (path + 1, '/'); + *rem_path = strchr (path + 1, '/'); if (internal) - rem_path = strchr (path + 1, '/'); + *rem_path = strchr (path + 1, '/'); } /** @@ -643,7 +646,7 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } strcpy (real_path, priv->brick_path); - remove_trash_path (tmp_path, (frame->root->pid < 0), tmp_stat); + remove_trash_path (tmp_path, (frame->root->pid < 0), &tmp_stat); if (tmp_stat) strcat (real_path, tmp_stat); STACK_WIND_COOKIE (frame, trash_unlink_mkdir_cbk, tmp_path, @@ -713,7 +716,7 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } strcpy (real_path, priv->brick_path); - remove_trash_path (tmp_path, (frame->root->pid < 0), tmp_stat); + remove_trash_path (tmp_path, (frame->root->pid < 0), &tmp_stat); if (tmp_stat) strcat (real_path, tmp_stat); @@ -784,7 +787,7 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } strcpy (real_path, priv->brick_path); - remove_trash_path (tmp_str, (frame->root->pid < 0), tmp_stat); + remove_trash_path (tmp_str, (frame->root->pid < 0), &tmp_stat); if (tmp_stat) strcat (real_path, tmp_stat); /* create the directory with proper permissions */ @@ -1230,7 +1233,7 @@ trash_truncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } strcpy (real_path, priv->brick_path); - remove_trash_path (tmp_path, (frame->root->pid < 0), tmp_stat); + remove_trash_path (tmp_path, (frame->root->pid < 0), &tmp_stat); if (tmp_stat) strcat (real_path, tmp_stat); /* create the directory with proper permissions */ @@ -1352,7 +1355,7 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } strcpy (real_path, priv->brick_path); - remove_trash_path (tmp_path, (frame->root->pid < 0), tmp_stat); + remove_trash_path (tmp_path, (frame->root->pid < 0), &tmp_stat); if (tmp_stat) strcat (real_path, tmp_stat); STACK_WIND_COOKIE (frame, trash_truncate_mkdir_cbk, @@ -1422,7 +1425,7 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } strcpy (real_path, priv->brick_path); - remove_trash_path (tmp_path, (frame->root->pid < 0), tmp_stat); + remove_trash_path (tmp_path, (frame->root->pid < 0), &tmp_stat); if (tmp_stat) strcat (real_path, tmp_stat); -- cgit