[PATCH v6] posix: Deprecate group_member for Linux
Florian Weimer
fweimer@redhat.com
Wed Dec 13 10:36:43 GMT 2023
* 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.
Thanks,
Florian
More information about the Libc-alpha
mailing list