bug-coreutils
[Top][All Lists]
Advanced

[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 wouldn’t 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)
            {







reply via email to

[Prev in Thread] Current Thread [Next in Thread]