This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/1] stdlib/tst-secure-getenv: handle >64 groups


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

Yes, that's indeed a test bug.

> ---
>  stdlib/tst-secure-getenv.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/stdlib/tst-secure-getenv.c b/stdlib/tst-secure-getenv.c
> index 74580b889a..178dfa0439 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 = malloc (count * sizeof (*groups));

This should be xcalloc (or perhaps xreallocarray, if we had support for
that).

>    int ret = getgroups (count, groups);

Technically, you would also need to add a loop to retry because the
probing for size could have returned an outdated value.

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]