1 Star 0 Fork 48

maqi/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0229-Call-getgroups-to-know-size-of-supplementary-groups-.patch 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
张彬琛 提交于 2021-01-20 13:59 . import systemd-239-29.el8.src.rpm
From e1bd03e75860fb349a6de589bbb1274acc454aef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
Date: Fri, 13 Sep 2019 11:18:18 +0200
Subject: [PATCH] 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
(cherry picked from commit f5e0b942af1e86993c21f4e5c84342bb10403dac)
Resolves: #1743235
---
src/basic/user-util.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
index a562a397c7..c533f67025 100644
--- a/src/basic/user-util.c
+++ b/src/basic/user-util.c
@@ -358,9 +358,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;
@@ -371,12 +370,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;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/maqi77/systemd.git
git@gitee.com:maqi77/systemd.git
maqi77
systemd
systemd
a8

搜索帮助