From 03437fc93657717edcdb30083d8bed60c0a97b29 Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Mon, 10 Mar 2025 14:52:22 +0100 Subject: [PATCH] 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 --- src/bin/copy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bin/copy.c b/src/bin/copy.c index 680d0a70..6e54b079 100644 --- a/src/bin/copy.c +++ b/src/bin/copy.c @@ -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");