teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0798-Call-getgroups-to-know-size-of-supplementary-groups-.patch

ff2b41
From 0d0ba7ee44d652c23e6027fe3b1c1ee8e2f65a25 Mon Sep 17 00:00:00 2001
ff2b41
From: systemd team <systemd-maint@redhat.com>
ff2b41
Date: Mon, 19 Aug 2019 13:51:48 +0200
ff2b41
Subject: [PATCH] Call getgroups() to know size of supplementary groups array
ff2b41
 to allocate
ff2b41
ff2b41
Resolves RHBZ #1743230 - journalctl dumps core when stack limit is reduced to 256 KB
ff2b41
---
ff2b41
 src/shared/util.c | 13 ++++++++-----
ff2b41
 1 file changed, 8 insertions(+), 5 deletions(-)
ff2b41
ff2b41
diff --git a/src/shared/util.c b/src/shared/util.c
ff2b41
index 127a64c3c6..ce6678eb38 100644
ff2b41
--- a/src/shared/util.c
ff2b41
+++ b/src/shared/util.c
ff2b41
@@ -5097,7 +5097,7 @@ int get_group_creds(const char **groupname, gid_t *gid) {
ff2b41
 
ff2b41
 int in_gid(gid_t gid) {
ff2b41
         gid_t *gids;
ff2b41
-        int ngroups_max, r, i;
ff2b41
+        int ngroups, r, i;
ff2b41
 
ff2b41
         if (getgid() == gid)
ff2b41
                 return 1;
ff2b41
@@ -5105,12 +5105,15 @@ int in_gid(gid_t gid) {
ff2b41
         if (getegid() == gid)
ff2b41
                 return 1;
ff2b41
 
ff2b41
-        ngroups_max = sysconf(_SC_NGROUPS_MAX);
ff2b41
-        assert(ngroups_max > 0);
ff2b41
+        ngroups = getgroups(0, NULL);
ff2b41
+        if (ngroups < 0)
ff2b41
+                return -errno;
ff2b41
+        if (ngroups == 0)
ff2b41
+                return 0;
ff2b41
 
ff2b41
-        gids = alloca(sizeof(gid_t) * ngroups_max);
ff2b41
+        gids = alloca(sizeof(gid_t) * ngroups);
ff2b41
 
ff2b41
-        r = getgroups(ngroups_max, gids);
ff2b41
+        r = getgroups(ngroups, gids);
ff2b41
         if (r < 0)
ff2b41
                 return -errno;
ff2b41