[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS
From: |
Steven Parkes |
Subject: |
RE: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS |
Date: |
Wed, 8 Apr 2009 10:32:19 -0700 |
Very similar to my "correct" patch. There's one other issue I found when I
was coming up with a patch which is that Darwin:getgrouplist also doesn't
return the number of groups. It sets the in/out parameter, but then just
returns 0.
The only thing I wasn't too sure about was how risky it is to just keep
doubling. If some bizzaro-world getgrouplist was just implemented to return
-1, well, the results wouldnt be great. But maybe that's not a significant
concern.
My patch:
diff --git a/gl/lib/mgetgroups.c b/gl/lib/mgetgroups.c
index e697013..8d08ae8 100644
--- a/gl/lib/mgetgroups.c
+++ b/gl/lib/mgetgroups.c
@@ -83,7 +83,17 @@ mgetgroups (char const *username, gid_t gid, GETGROUPS_T
**groups)
GETGROUPS_T *h;
/* getgrouplist updates max_n_groups to num required. */
+ /* Some old getgrouplist return -1 but don't update max_n_groups
*/
+ int previous_max_n_groups = max_n_groups;
ng = getgrouplist (username, gid, g, &max_n_groups);
+
+ if (ng < 0 && max_n_groups == previous_max_n_groups)
+ {
+ max_n_groups <<= 1;
+ } else {
+ /* some old getgrouplist don't return max_n_groups on success
*/
+ ng = max_n_groups;
+ }
if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)
{
- inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Steven Parkes, 2009/04/07
- RE: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Steven Parkes, 2009/04/07
- Re: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Pádraig Brady, 2009/04/08
- RE: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS,
Steven Parkes <=
- Re: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Pádraig Brady, 2009/04/08
- RE: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Steven Parkes, 2009/04/08
- Re: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Jim Meyering, 2009/04/09
- Re: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Pádraig Brady, 2009/04/09
- Re: inifite loop in recent mgetgroups.c:mgetgroups on Darwin/MacOS, Jim Meyering, 2009/04/09