Patchwork [v2] stdlib/tst-secure-getenv: handle >64 groups

login
register
mail settings
Submitter Mike Gerow
Date April 5, 2019, 7:51 p.m.
Message ID <20190405195135.GA20514@google.com>
Download mbox | patch
Permalink /patch/32173/
State New
Headers show

Comments

Mike Gerow - April 5, 2019, 7:51 p.m.
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.
---
 stdlib/tst-secure-getenv.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Florian Weimer - April 16, 2019, 12:43 p.m.
* Mike Gerow:

> 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.

Looks good.  Do you have commit access?  If not, I can add a ChangeLog
entry and push this on your behalf.

Thanks,
Florian
Mike Gerow - April 16, 2019, 6:18 p.m.
On Tue, Apr 16, 2019 at 02:43:53PM +0200, Florian Weimer wrote:
> Looks good.  Do you have commit access?  If not, I can add a ChangeLog
> entry and push this on your behalf.
I don't have commit access, so yes I'd really appreciate if you could
push this on my behalf.

Thanks in advance!
Florian Weimer - April 17, 2019, 9:51 a.m.
* Mike Gerow:

> On Tue, Apr 16, 2019 at 02:43:53PM +0200, Florian Weimer wrote:
>> Looks good.  Do you have commit access?  If not, I can add a ChangeLog
>> entry and push this on your behalf.
> I don't have commit access, so yes I'd really appreciate if you could
> push this on my behalf.

Fine, pushed.

Florian

Patch

diff --git a/stdlib/tst-secure-getenv.c b/stdlib/tst-secure-getenv.c
index 74580b889a..94de199530 100644
--- a/stdlib/tst-secure-getenv.c
+++ b/stdlib/tst-secure-getenv.c
@@ -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;
 }