13 Star 9 Fork 91

src-openEuler / systemd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-core-exec-do-not-crash-with-UtmpMode-user-without-Us.patch 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
胡宇彪 提交于 2024-03-27 14:31 . sync patches from systemd community
From cba1060f8854fd9a11dac8e2b02126d2f3bb14ba Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 19 Feb 2024 13:04:28 +0900
Subject: [PATCH] core/exec: do not crash with UtmpMode=user without User=
setting
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2264404.
Replaces #31356.
(cherry picked from commit d42b81f93f81e45f7a4053c6522ec3a2145ff136)
Conflict:NA
Reference:https://github.com/systemd/systemd-stable/commit/cba1060f8854fd9a11dac8e2b02126d2f3bb14ba
---
src/core/exec-invoke.c | 12 +++++++++++-
src/shared/utmp-wtmp.c | 1 +
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c
index 70d963e269..9927e5d1e7 100644
--- a/src/core/exec-invoke.c
+++ b/src/core/exec-invoke.c
@@ -4340,6 +4340,16 @@ int exec_invoke(
#if ENABLE_UTMP
if (context->utmp_id) {
+ _cleanup_free_ char *username_alloc = NULL;
+
+ if (!username && context->utmp_mode == EXEC_UTMP_USER) {
+ username_alloc = uid_to_name(uid_is_valid(uid) ? uid : saved_uid);
+ if (!username_alloc) {
+ *exit_status = EXIT_USER;
+ return log_oom();
+ }
+ }
+
const char *line = context->tty_path ?
(path_startswith(context->tty_path, "/dev/") ?: context->tty_path) :
NULL;
@@ -4348,7 +4358,7 @@ int exec_invoke(
context->utmp_mode == EXEC_UTMP_INIT ? INIT_PROCESS :
context->utmp_mode == EXEC_UTMP_LOGIN ? LOGIN_PROCESS :
USER_PROCESS,
- username);
+ username ?: username_alloc);
}
#endif
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
index 6c3238a9c6..267b350276 100644
--- a/src/shared/utmp-wtmp.c
+++ b/src/shared/utmp-wtmp.c
@@ -179,6 +179,7 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line
int r;
assert(id);
+ assert(ut_type != USER_PROCESS || user);
init_timestamp(&store, 0);
--
2.33.0
1
https://gitee.com/src-openeuler/systemd.git
git@gitee.com:src-openeuler/systemd.git
src-openeuler
systemd
systemd
master

搜索帮助