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