From abc309bee6007ed47a2aee33705324dc9cc8050a Mon Sep 17 00:00:00 2001 From: tjg Date: Tue, 20 Aug 2002 15:38:52 +0000 Subject: Bug: don't call ealloc(0) on systems where getgroups() doesn't return egid (thanks Chris Siebenmann). --- ChangeLog | 5 +++++ nalloc.c | 4 +++- which.c | 14 +++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d06a7b5..52e9777 100644 --- a/ChangeLog +++ b/ChangeLog @@ -807,3 +807,8 @@ Changes since rc-1.5b2 hand a garbage signal mask to sigaction() (thanks Jeremy Fitzhardinge). Also, remove use of SA_INTERRUPT (SUSv3, BSD, etc. have SA_RESTART with the inverted meaning). + +2002-08-20 + + Bug: don't call ealloc(0) on systems where getgroups() doesn't + return egid (thanks Chris Siebenmann). diff --git a/nalloc.c b/nalloc.c index eb621e0..0144b48 100644 --- a/nalloc.c +++ b/nalloc.c @@ -112,8 +112,10 @@ extern void restoreblock(Block *old) { /* generic memory allocation functions */ extern void *ealloc(size_t n) { - void *p = malloc(n); + void *p; + assert(n); + p = malloc(n); if (p == NULL) { uerror("malloc"); rc_exit(1); diff --git a/which.c b/which.c index 9a6e1bb..8abdc60 100644 --- a/which.c +++ b/which.c @@ -37,6 +37,8 @@ static int ingidset(gid_t g) { return 1; return 0; } +#else +#define ingidset(g) (FALSE) #endif /* @@ -56,11 +58,7 @@ static bool rc_access(char *path, bool verbose) { mask = X_ALL; else if (uid == st.st_uid) mask = X_USR; -#if HAVE_GETGROUPS else if (gid == st.st_gid || ingidset(st.st_gid)) -#else - else if (gid == st.st_gid) -#endif mask = X_GRP; else mask = X_OTH; @@ -93,10 +91,12 @@ extern char *which(char *name, bool verbose) { rc_exit(1); } #else - ngroups = NGROUPS; + ngroups = NGROUPS; #endif - gidset = ealloc(ngroups * sizeof(GETGROUPS_T)); - getgroups(ngroups, gidset); + if (ngroups) { + gidset = ealloc(ngroups * sizeof(GETGROUPS_T)); + getgroups(ngroups, gidset); + } #endif } if (isabsolute(name)) /* absolute pathname? */ -- cgit v1.2.3