From e848410ab6d13871be6b57101788ea5183efe75c Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Fri, 13 Oct 2017 11:46:38 +0530 Subject: stack.h: make sure 'oldgroups' is never null If 'oldgroups' is null, it can lead to a crash. Change-Id: I7a4f71256b07dc0ca3b988cad3694c21b150c99e BUG: 789278 Signed-off-by: Amar Tumballi --- libglusterfs/src/stack.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h index ddad46c9673..856a9a4786e 100644 --- a/libglusterfs/src/stack.h +++ b/libglusterfs/src/stack.h @@ -428,13 +428,24 @@ copy_frame (call_frame_t *frame) newstack->uid = oldstack->uid; newstack->gid = oldstack->gid; newstack->pid = oldstack->pid; - newstack->ngrps = oldstack->ngrps; newstack->op = oldstack->op; newstack->type = oldstack->type; if (call_stack_alloc_groups (newstack, oldstack->ngrps) != 0) { mem_put (newstack); return NULL; } + if (!oldstack->groups) { + gf_msg_debug ("stack", EINVAL, "groups is null (ngrps: %d)", + oldstack->ngrps); + /* Considering 'groups' is NULL, set ngrps to 0 */ + oldstack->ngrps = 0; + + if (oldstack->groups_large) + oldstack->groups = oldstack->groups_large; + else + oldstack->groups = oldstack->groups_small; + } + newstack->ngrps = oldstack->ngrps; memcpy (newstack->groups, oldstack->groups, sizeof (gid_t) * oldstack->ngrps); newstack->unique = oldstack->unique; -- cgit