From: Karel Zak Date: Mon, 21 Dec 2015 14:50:58 +0000 (+0100) Subject: lslogins: fix getgrouplist() usage for 64BE X-Git-Tag: v2.28-rc1~217 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8b7ef916893de143828d2e2670020d955887bb22;p=thirdparty%2Futil-linux.git lslogins: fix getgrouplist() usage for 64BE 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 --- diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index 65129658d0..f9b9d401d8 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -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; }