Clean up get_groups: don't ever allocate dynamically, and remove

potential trouble spot where it used to call itself recursively
without looking at the return value.
This commit is contained in:
sperber 2003-02-17 16:06:20 +00:00
parent 33c1b8fb0e
commit 6dcdd107e0
1 changed files with 6 additions and 19 deletions

View File

@ -804,33 +804,20 @@ s48_value scsh_setegid(s48_value gid)
s48_value get_groups()
{
int retval;
int veclen = getgroups(0,NULL);
gid_t gvec[NGROUPS_MAX + 1];
int veclen = getgroups(NGROUPS_MAX + 1, gvec);
int i = veclen;
s48_value l = S48_NULL;
gid_t gvec0[20], *gp = gvec0;
if( veclen > 20 )
if (NULL == (gp=Malloc(gid_t,veclen))) s48_raise_os_error(errno);
retval = getgroups(veclen, gp);
if (retval == -1){
if (veclen > 20) Free(gp);
if (veclen == -1)
s48_raise_os_error(errno);
}
else if (retval != veclen){ /* paranoia... */
get_groups();
}
else{
else {
S48_DECLARE_GC_PROTECT(1);
S48_GC_PROTECT_1(l);
while (i > 0){
l = s48_cons(s48_enter_integer(gp[--i]), l);
}
while (i > 0)
l = s48_cons(s48_enter_integer(gvec[--i]), l);
if (veclen > 20) Free(gp);
S48_GC_UNPROTECT();
return l;