]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/addgrps.c: add_groups(): Allocate earlier
authorAlejandro Colomar <alx@kernel.org>
Thu, 14 Nov 2024 17:18:40 +0000 (18:18 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 24 Jan 2025 13:58:13 +0000 (07:58 -0600)
This will allow using lsearch(3).

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/addgrps.c

index 0a38d861bc98cd9cf5b9e1783744e02f89fb4079..b64fa4978d85f43717ffd9351764b74c32c17b83 100644 (file)
@@ -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;