summaryrefslogtreecommitdiffstats
path: root/src/basic/user-util.c
diff options
context:
space:
mode:
authorRenaud Métrich <rmetrich@redhat.com>2019-09-13 11:18:18 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-09-16 08:51:36 +0200
commitf5e0b942af1e86993c21f4e5c84342bb10403dac (patch)
treea629d0401c5f1965ef4f2890086cbfd3fb97d546 /src/basic/user-util.c
parentpo: update Polish translation (diff)
downloadsystemd-f5e0b942af1e86993c21f4e5c84342bb10403dac.tar.xz
systemd-f5e0b942af1e86993c21f4e5c84342bb10403dac.zip
Call getgroups() to know size of supplementary groups array to allocate
Resolves RHBZ #1743230 - journalctl dumps core when stack limit is reduced to 256 KB
Diffstat (limited to 'src/basic/user-util.c')
-rw-r--r--src/basic/user-util.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
index 3b253bc264..957285c091 100644
--- a/src/basic/user-util.c
+++ b/src/basic/user-util.c
@@ -410,9 +410,8 @@ char* gid_to_name(gid_t gid) {
}
int in_gid(gid_t gid) {
- long ngroups_max;
gid_t *gids;
- int r, i;
+ int ngroups, r, i;
if (getgid() == gid)
return 1;
@@ -423,12 +422,15 @@ int in_gid(gid_t gid) {
if (!gid_is_valid(gid))
return -EINVAL;
- ngroups_max = sysconf(_SC_NGROUPS_MAX);
- assert(ngroups_max > 0);
+ ngroups = getgroups(0, NULL);
+ if (ngroups < 0)
+ return -errno;
+ if (ngroups == 0)
+ return 0;
- gids = newa(gid_t, ngroups_max);
+ gids = newa(gid_t, ngroups);
- r = getgroups(ngroups_max, gids);
+ r = getgroups(ngroups, gids);
if (r < 0)
return -errno;