aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorMike Gerow <gerow@google.com>2019-04-17 11:45:34 +0200
committerFlorian Weimer <fweimer@redhat.com>2019-04-17 11:45:34 +0200
commitbae8cf0e930d82133e96c4e2547548ed53938de1 (patch)
tree103d0087cefc65801b2f5bffac5b5941bf44893d /stdlib
parent6b5c8607a4bda18b48765f0a3eb84b96525dcaf1 (diff)
downloadglibc-bae8cf0e930d82133e96c4e2547548ed53938de1.zip
glibc-bae8cf0e930d82133e96c4e2547548ed53938de1.tar.gz
glibc-bae8cf0e930d82133e96c4e2547548ed53938de1.tar.bz2
stdlib/tst-secure-getenv: handle >64 groups
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.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/tst-secure-getenv.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/stdlib/tst-secure-getenv.c b/stdlib/tst-secure-getenv.c
index 74580b8..94de199 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;
}