[OLPC-devel] [PATCH] Fail gracefully if getgroups() fails
Jordan Crouse
jordan.crouse at amd.com
Tue Aug 22 14:17:56 EDT 2006
uClibc is pretty stuck on using legacy 16 bit UIDs. So when one turns off
CONFIG_UID16 in the Linux kernel, some syscalls have the annoying tendency to
return an error when they aren't normally expected to, including getgroups().
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 at firmworks.com>
-------------- next part --------------
[PATCH]: coreutils/test.c - fail gracefully if getgroups() fails.
Avoid a memory error if getgroups() returns a -1.
---
Index: busybox-1.1.3/coreutils/test.c
===================================================================
--- busybox-1.1.3.orig/coreutils/test.c 2006-08-22 08:28:57.000000000 -0600
+++ busybox-1.1.3/coreutils/test.c 2006-08-22 08:40:01.000000000 -0600
@@ -540,8 +540,11 @@
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 = xrealloc(group_array, ngroups * sizeof(gid_t));
+ getgroups(ngroups, group_array);
+ }
}
/* Return non-zero if GID is one that we have in our groups list. */
More information about the Devel
mailing list