Skip to content

Commit

Permalink
lib/addgrps.c: add_groups(): Remove arbitrary limit
Browse files Browse the repository at this point in the history
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
  • Loading branch information
alejandro-colomar authored and hallyn committed Jan 24, 2025
1 parent 7be3b4c commit 476dbe5
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/addgrps.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@ int
add_groups(const char *list)
{
GETGROUPS_T *gids;
char *g, *p;
char buf[1024];
char *g, *p, *dup;
FILE *shadow_logfd = log_get_logfd();
size_t n;
ssize_t n0;

if (strlen (list) >= sizeof (buf)) {
errno = EINVAL;
return -1;
}
strcpy (buf, list);

n0 = getgroups(0, NULL);
if (n0 == -1)
return -1;
Expand All @@ -62,8 +55,11 @@ add_groups(const char *list)
if (gids == NULL)
return -1;

p = dup = strdup(list);
if (dup == NULL)
goto free_gids;

n = n0;
p = buf;
while (NULL != (g = strsep(&p, ",:"))) {
struct group *grp;

Expand All @@ -75,6 +71,7 @@ add_groups(const char *list)

LSEARCH(&grp->gr_gid, gids, &n);
}
free(dup);

if (setgroups(n, gids) == -1) {
fprintf(shadow_logfd, "setgroups: %s\n", strerror(errno));
Expand Down

0 comments on commit 476dbe5

Please sign in to comment.