Welcome to little lamb

Code » slicd » commit 1a76bba

Fix possible error to get supplementary groups

author Olivier Brunel
2018-10-31 23:22:05 UTC
committer Olivier Brunel
2018-10-31 23:22:05 UTC
parent f67bc646388709a201074f90e6588b59eacbab2f

Fix possible error to get supplementary groups

That is, one could get an error to get supplementary groups (EINVAL)
even though there's no reason for it. This is because errno was only set
to zero before looping on getgrent() instead of before each call, and as
it turns out it is (now) possible for getgrent() to set errno in case of
success (when linking glibc at least), which would thus lead us to
falsely believe an error occurred.

src/extra/setuid.c +1 -1

diff --git a/src/extra/setuid.c b/src/extra/setuid.c
index 1a240d0..a76dc71 100644
--- a/src/extra/setuid.c
+++ b/src/extra/setuid.c
@@ -99,12 +99,12 @@ main (int argc, char * const argv[])
         gid_t gids[NGROUPS_MAX];
         int n = 0;
 
-        errno = 0;
         for (;;)
         {
             struct group *gr;
             register char **member;
 
+            errno = 0;
             gr = getgrent ();
             if (!gr)
                 break;