diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-12-28 21:19:58 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-12-28 21:19:58 +0000 |
commit | ba56672d0f0932384b3b749b48173f14ae9dc6fc (patch) | |
tree | d8a882b9cf91df32cfe0c5c540c5bc89dac4dd65 /libc/sysdeps/linux/common | |
parent | 8f7b38133bb46cb5fa211ae97e3d22d1f76dcb8f (diff) |
make sure we handle the (malloc(0)==NULL) case as Aubrey points out via the e-mail list
Diffstat (limited to 'libc/sysdeps/linux/common')
-rw-r--r-- | libc/sysdeps/linux/common/getgroups.c | 6 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/setgroups.c | 13 |
2 files changed, 12 insertions, 7 deletions
diff --git a/libc/sysdeps/linux/common/getgroups.c b/libc/sysdeps/linux/common/getgroups.c index 92cdca2d0..83d92627e 100644 --- a/libc/sysdeps/linux/common/getgroups.c +++ b/libc/sysdeps/linux/common/getgroups.c @@ -32,7 +32,7 @@ ret_error: size = MIN(size, sysconf(_SC_NGROUPS_MAX)); kernel_groups = (__kernel_gid_t *)malloc(sizeof(*kernel_groups) * size); - if (kernel_groups == NULL) + if (size && kernel_groups == NULL) goto ret_error; ngids = __syscall_getgroups(size, kernel_groups); @@ -41,7 +41,9 @@ ret_error: groups[i] = kernel_groups[i]; } } - free(kernel_groups); + + if (kernel_groups) + free(kernel_groups); return ngids; } } 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; } } |