From: Alejandro Colomar Date: Thu, 14 Nov 2024 17:18:40 +0000 (+0100) Subject: lib/addgrps.c: add_groups(): Allocate earlier X-Git-Tag: 4.17.3~45 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=1fd1bb4c4a6e90a4116a929893e897895a0b38cc;p=thirdparty%2Fshadow.git lib/addgrps.c: add_groups(): Allocate earlier This will allow using lsearch(3). Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/addgrps.c b/lib/addgrps.c index 0a38d861b..b64fa4978 100644 --- a/lib/addgrps.c +++ b/lib/addgrps.c @@ -70,6 +70,10 @@ add_groups(const char *list) continue; } + grouplist = REALLOCF(grouplist, ngroups + 1, GETGROUPS_T); + if (grouplist == NULL) + return -1; + if (LFIND(&grp->gr_gid, grouplist, ngroups) != NULL) continue; @@ -77,10 +81,7 @@ add_groups(const char *list) fputs (_("Warning: too many groups\n"), shadow_logfd); break; } - grouplist = REALLOCF(grouplist, ngroups + 1, GETGROUPS_T); - if (grouplist == NULL) { - return -1; - } + grouplist[ngroups] = grp->gr_gid; ngroups++; added = true;