]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/addgrps.c: add_groups(): Split variable to avoid sign-mismatch diagnostics
authorAlejandro Colomar <alx@kernel.org>
Thu, 14 Nov 2024 18:29:04 +0000 (19:29 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 24 Jan 2025 13:58:13 +0000 (07:58 -0600)
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/addgrps.c

index 70ccd5a455a04a1f35009a11b4a2edb8238b5755..88a9710bca84f3433ec7a2fa1e1de9f171ddbf63 100644 (file)
@@ -38,7 +38,8 @@ add_groups(const char *list)
        char *g, *p;
        char buf[1024];
        FILE *shadow_logfd = log_get_logfd();
-       size_t  ngroups;
+       size_t  n;
+       ssize_t n0;
 
        if (strlen (list) >= sizeof (buf)) {
                errno = EINVAL;
@@ -46,18 +47,19 @@ add_groups(const char *list)
        }
        strcpy (buf, list);
 
-       ngroups = getgroups(0, NULL);
-       if (ngroups == -1)
+       n0 = getgroups(0, NULL);
+       if (n0 == -1)
                return -1;
 
-       grouplist = MALLOC(ngroups, GETGROUPS_T);
+       grouplist = MALLOC(n0, GETGROUPS_T);
        if (grouplist == NULL)
                return -1;
 
-       ngroups = getgroups(ngroups, grouplist);
-       if (ngroups == -1)
+       n0 = getgroups(n0, grouplist);
+       if (n0 == -1)
                goto free_gids;
 
+       n = n0;
        p = buf;
        while (NULL != (g = strsep(&p, ",:"))) {
                struct group  *grp;
@@ -68,14 +70,14 @@ add_groups(const char *list)
                        continue;
                }
 
-               grouplist = REALLOCF(grouplist, ngroups + 1, GETGROUPS_T);
+               grouplist = REALLOCF(grouplist, n + 1, GETGROUPS_T);
                if (grouplist == NULL)
                        return -1;
 
-               LSEARCH(&grp->gr_gid, grouplist, &ngroups);
+               LSEARCH(&grp->gr_gid, grouplist, &n);
        }
 
-       if (setgroups(ngroups, grouplist) == -1) {
+       if (setgroups(n, grouplist) == -1) {
                fprintf(shadow_logfd, "setgroups: %s\n", strerror(errno));
                goto free_gids;
        }