[PATCH v2] group_member: Get rid of unbounded alloca.

Florian Weimer fweimer@redhat.com
Wed Aug 9 09:43:18 GMT 2023


* Joe Simmons-Talbott via Libc-alpha:

>  int
>  __group_member (gid_t gid)
>  {
> +  int n;
>    gid_t *groups;
> +  struct scratch_buffer buf;
> +  scratch_buffer_init (&buf);
> +
> +  n = __getgroups (0, NULL);
> +  if (!scratch_buffer_set_array_size (&buf, n, sizeof (*groups)))
> +    abort ();
> +  groups = buf.data;
>  
> +  n = __getgroups (n, groups);
>  
>    while (n-- > 0)
>      if (groups[n] == gid)
> +      {
> +	scratch_buffer_free (&buf);
> +        return 1;
> +      }
>  
> +  scratch_buffer_free (&buf);
>    return 0;
>  }

The abort isn't ideal.  Should we deprecate this function because it
cannot be implemented correctly?

Typically, Linux supports up to 65,536 supplementary groups, so a memory
allocation may indeed be required.  Hurd can implement it without
allocation.

Thanks,
Florian



More information about the Libc-alpha mailing list