[PATCH v6] posix: Deprecate group_member for Linux

Joe Simmons-Talbott josimmon@redhat.com
Wed Dec 13 15:36:30 GMT 2023


On Wed, Dec 13, 2023 at 11:36:43AM +0100, Florian Weimer wrote:
> * Joe Simmons-Talbott:
> 
> > +int
> > +__group_member2 (gid_t gid)
> > +{
> > +  int n, size;
> > +  gid_t *groups;
> > +  struct scratch_buffer sbuf;
> > +  scratch_buffer_init (&sbuf);
> > +
> > +  size = NGROUPS_MAX;
> > +  do
> > +    {
> > +      if (!scratch_buffer_set_array_size (&sbuf, sizeof (*groups), size))
> > +	return -1;
> > +      groups = sbuf.data;
> > +
> > +      n = __getgroups (size, groups);
> > +      size *= 2;
> > +    }
> > +  while (n == size / 2);
> 
> This doesn't look quite right to me, sorry.  The initial size we use for
> getgroups should be based on the scratch buffer default, not the value
> for NGROUPS_MAX.
> 
> In the loop, we should call getgroups with 0, use that to resize the
> scratch array, and then call getgroups again with that size.  The loop
> is still required because setgroups is eventually supposed to be
> async-signal-safe by analogy.

Thank you for the review.  I've sent an updated v7 patch [1] with your
suggested changes.

Thanks,
Joe

[1] https://sourceware.org/pipermail/libc-alpha/2023-December/153290.html



More information about the Libc-alpha mailing list