From ba56672d0f0932384b3b749b48173f14ae9dc6fc Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 28 Dec 2005 21:19:58 +0000 Subject: make sure we handle the (malloc(0)==NULL) case as Aubrey points out via the e-mail list --- libc/sysdeps/linux/common/setgroups.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'libc/sysdeps/linux/common/setgroups.c') diff --git a/libc/sysdeps/linux/common/setgroups.c b/libc/sysdeps/linux/common/setgroups.c index 3d2102f9d..49d85156f 100644 --- a/libc/sysdeps/linux/common/setgroups.c +++ b/libc/sysdeps/linux/common/setgroups.c @@ -26,11 +26,13 @@ ret_error: return -1; } else { size_t i; - __kernel_gid_t *kernel_groups; + __kernel_gid_t *kernel_groups = NULL; - kernel_groups = (__kernel_gid_t *)malloc(sizeof(*kernel_groups) * size); - if (kernel_groups == NULL) - goto ret_error; + if (size) { + kernel_groups = (__kernel_gid_t *)malloc(sizeof(*kernel_groups) * size); + if (kernel_groups == NULL) + goto ret_error; + } for (i = 0; i < size; i++) { kernel_groups[i] = (groups)[i]; @@ -40,7 +42,8 @@ ret_error: } i = __syscall_setgroups(size, kernel_groups); - free(kernel_groups); + if (kernel_groups) + free(kernel_groups); return i; } } -- cgit v1.2.3