diff options
author | Rob Landley | 2006-08-22 23:40:28 +0000 |
---|---|---|
committer | Rob Landley | 2006-08-22 23:40:28 +0000 |
commit | ecb29573e9d2caf59de17fcb4efff129b35ad792 (patch) | |
tree | be1be2a0dadab03bb2ca20751b0c60524a53dcb1 /coreutils | |
parent | 98a915713d8d07dccd47067869978ec73543cbfc (diff) | |
download | busybox-ecb29573e9d2caf59de17fcb4efff129b35ad792.zip busybox-ecb29573e9d2caf59de17fcb4efff129b35ad792.tar.gz |
"Jordan Crouse" <jordan.crouse@amd.com> says:
The following patch makes coreutils/test.c act fail gracefully if getgroups()
returns a -1. This fixes a problem on the One Laptop Per Child ROM image
whereby we were getting odd Memory exhausted messages for '[' and 'test'.
Found by Mitch Bradley <wmb@firmworks.com>
(Tweaked by Rob: no need to initialize a static to NULL, or realloc something
that's only allocated when it's NULL.)
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/test.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/coreutils/test.c b/coreutils/test.c index bbc8022..c1097c2 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -151,7 +151,7 @@ typedef int arith_t; static char **t_wp; static struct t_op const *t_wp_op; -static gid_t *group_array = NULL; +static gid_t *group_array; static int ngroups; static enum token t_lex(char *s); @@ -547,8 +547,10 @@ static int test_eaccess(char *path, int mode) static void initialize_group_array(void) { ngroups = getgroups(0, NULL); - group_array = xrealloc(group_array, ngroups * sizeof(gid_t)); - getgroups(ngroups, group_array); + if (ngroups > 0) { + group_array = xmalloc(ngroups * sizeof(gid_t)); + getgroups(ngroups, group_array); + } } /* Return non-zero if GID is one that we have in our groups list. */ |