]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslogins: fix getgrouplist() usage for 64BE
authorKarel Zak <kzak@redhat.com>
Mon, 21 Dec 2015 14:50:58 +0000 (15:50 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 21 Dec 2015 14:50:58 +0000 (15:50 +0100)
on ppc64:
 $ lslogins kzak
 $ lslogins: cannot allocate 85899345920 bytes: Cannot allocate memory

because

  (int *) len

where len is pointer to size_t is bad idea...

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/lslogins.c

index 65129658d06636940567555cb2f336a52dbdf18d..f9b9d401d81c95fa8fe89bd67959497a201a6848 100644 (file)
@@ -528,21 +528,24 @@ static int parse_btmp(struct lslogins_control *ctl, char *path)
 static int get_sgroups(gid_t **list, size_t *len, struct passwd *pwd)
 {
        size_t n = 0;
+       int ngroups = 0;
 
        *len = 0;
        *list = NULL;
 
        /* first let's get a supp. group count */
-       getgrouplist(pwd->pw_name, pwd->pw_gid, *list, (int *) len);
-       if (!*len)
+       getgrouplist(pwd->pw_name, pwd->pw_gid, *list, &ngroups);
+       if (!ngroups)
                return -1;
 
-       *list = xcalloc(1, *len * sizeof(gid_t));
+       *list = xcalloc(1, ngroups * sizeof(gid_t));
 
        /* now for the actual list of GIDs */
-       if (-1 == getgrouplist(pwd->pw_name, pwd->pw_gid, *list, (int *) len))
+       if (-1 == getgrouplist(pwd->pw_name, pwd->pw_gid, *list, &ngroups))
                return -1;
 
+       *len = (size_t) ngroups;
+
        /* getgroups also returns the user's primary GID - dispose of it */
        while (n < *len) {
                if ((*list)[n] == pwd->pw_gid)
@@ -552,6 +555,7 @@ static int get_sgroups(gid_t **list, size_t *len, struct passwd *pwd)
 
        if (*len)
                (*list)[n] = (*list)[--(*len)];
+
        return 0;
 }