Excerpts from mail: (28-Apr-97) autoconf getgroups() test bugs by Roderick
Schertler
This code in autoconf:
{ gid_t groups[3*2];unsigned i;
for(i=getgroups(3,groups);--i<3&&groups[i]==getgid(););
if(i<3)
{ setegid(groups[i]);
if(!setrgid(groups[i])&&getgid()!=groups[i])
puts("#define setrgid_BRAIN_DAMAGE");
}
always fails for me because I'm in more than 3 groups.
Also, I think the <3 test is buggy, I think it should be >=0 in both
places. The tests as written are always true because the return from
getgroups() is at most 3 and i is decremented before testing, plus
there's nothing there to prevent i from dropping below 0 and the loop
never stopping.
I had the same problem with this autoconf test on a DEC OSF/1 3.x system in
3.11pre4 and reported the problem to Stephen last June. He sent me a revised
autoconf that fixed the problem. Maybe it accidentally didn't get included
into the distribution? Alas, I can't seem to find the fixed version.
At least on DEC OSF/1 3.x systems (and others, I presume), getgroups(x,y)
will return -1 if x is non-zero and smaller than the number of groups in the
supplementary group set. So, I think you're right. If you're in more than
three groups, it can't possibly work. The only fix I can think of at the top
of my head is to declare groups to have NGROUPS_MAX entries and use
NGROUPS_MAX instead of 3 in the call to getgroups(). Also, the test should
probably guard against i being negative... But I haven't tested any of this
yet. I'm still using 3.11pre4. I guess I should try to build 3.11pre7 before
it goes final.