summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2015-12-21 15:50:58 +0100
committerKarel Zak2015-12-21 15:50:58 +0100
commit8b7ef916893de143828d2e2670020d955887bb22 (patch)
tree98b490c227142e7640d4a31276c6cb7ef7d040f4
parenttravis: workaround env pollution, PYTHON_CFLAGS (diff)
downloadkernel-qcow2-util-linux-8b7ef916893de143828d2e2670020d955887bb22.tar.gz
kernel-qcow2-util-linux-8b7ef916893de143828d2e2670020d955887bb22.tar.xz
kernel-qcow2-util-linux-8b7ef916893de143828d2e2670020d955887bb22.zip
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 <kzak@redhat.com>
-rw-r--r--login-utils/lslogins.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index 65129658d..f9b9d401d 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;
}