From: Alejandro Colomar Date: Thu, 14 Nov 2024 18:22:16 +0000 (+0100) Subject: lib/, src/: Replace redundant checks by actual error handling X-Git-Tag: 4.17.3~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=258265941b52a5d60c67bd0a99c35dd096d5305f;p=thirdparty%2Fshadow.git lib/, src/: Replace redundant checks by actual error handling setgroups(2) already performs a test to check if the number of groups is too large. Don't do that ourselves, and also don't do it for every iteration. Just let setgroups(2) do it once. Instead of our check, let's report errors from setgroups(2). Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/addgrps.c b/lib/addgrps.c index c45c52996..630bff8c6 100644 --- a/lib/addgrps.c +++ b/lib/addgrps.c @@ -75,17 +75,14 @@ add_groups(const char *list) if (LFIND(&grp->gr_gid, grouplist, ngroups) != NULL) continue; - if (ngroups >= sysconf (_SC_NGROUPS_MAX)) { - fputs (_("Warning: too many groups\n"), shadow_logfd); - break; - } - grouplist[ngroups] = grp->gr_gid; ngroups++; } - if (setgroups(ngroups, grouplist) == -1) + if (setgroups(ngroups, grouplist) == -1) { + fprintf(shadow_logfd, "setgroups: %s\n", strerror(errno)); goto free_gids; + } free (grouplist); return 0; diff --git a/src/newgrp.c b/src/newgrp.c index 4c5795931..2b73ae01a 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -683,11 +683,7 @@ fail_gg: grouplist = XREALLOC(grouplist, ngroups + 1, GETGROUPS_T); if (LFIND(&gid, grouplist, ngroups) == NULL) { - if (ngroups >= sysconf (_SC_NGROUPS_MAX)) { - (void) fputs (_("too many groups\n"), stderr); - } else { - grouplist[ngroups++] = gid; - } + grouplist[ngroups++] = gid; } if (setgroups(ngroups, grouplist) == -1)