]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
stdlib/tst-secure-getenv: handle >64 groups
authorMike Gerow <gerow@google.com>
Wed, 17 Apr 2019 09:45:34 +0000 (11:45 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 17 Apr 2019 09:45:34 +0000 (11:45 +0200)
This test would fail unnecessarily if the user running it had more than
64 groups since getgroups returns EINVAL if the size provided is less
than the number of supplementary group IDs. Instead dynamically
determine the number of supplementary groups the user has.

ChangeLog
stdlib/tst-secure-getenv.c

index aaa413df6796b8537b294278577317b24417fd23..a23bdf29bdab202b31478e296a13127eb16ed03a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-17  Mike Gerow  <gerow@google.com>
+
+       * stdlib/tst-secure-getenv.c (choose_gid): Remove 64 supplemental
+       groups limit.
+
 2019-04-11  Florian Weimer  <fweimer@redhat.com>
 
        * resolv/nss_dns/dns-network.c (getanswer_r): Do not replace root
index 74580b889ab8aa762adb2b6991c64240d778fd01..94de199530c00af74be9ffd41b3266c21af3548b 100644 (file)
@@ -41,8 +41,14 @@ static char MAGIC_ARGUMENT[] = "run-actual-test";
 static gid_t
 choose_gid (void)
 {
-  const int count = 64;
-  gid_t groups[count];
+  int count = getgroups (0, NULL);
+  if (count < 0)
+    {
+      printf ("getgroups: %m\n");
+      exit (1);
+    }
+  gid_t *groups;
+  groups = xcalloc (count, sizeof (*groups));
   int ret = getgroups (count, groups);
   if (ret < 0)
     {
@@ -50,12 +56,17 @@ choose_gid (void)
       exit (1);
     }
   gid_t current = getgid ();
+  gid_t not_current = 0;
   for (int i = 0; i < ret; ++i)
     {
       if (groups[i] != current)
-       return groups[i];
+        {
+          not_current = groups[i];
+          break;
+        }
     }
-  return 0;
+  free (groups);
+  return not_current;
 }