bin: copy: use NGROUPS_MAX when probing user groups

Avoid a theoretical race between getting the number of groups a user
belongs to and actually processing them. We should not need to check
the return value of getgrouplist() as we know the number of groups fit
inside the buffer.

Signed-off-by: Richard Alpe <richard@bit42.se>
This commit is contained in:
Richard Alpe
2025-03-10 14:52:22 +01:00
parent 4998e320c5
commit 03437fc936
+1 -2
View File
@@ -114,8 +114,7 @@ static gid_t in_group(const char *user, const char *fn, gid_t *gid)
if (stat(dir, &st))
return 0;
getgrouplist(user, pw->pw_gid, NULL, &num);
num = NGROUPS_MAX;
groups = malloc(num * sizeof(gid_t));
if (!groups) {
perror("in_group() malloc");