mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
core/exec: do not crash with UtmpMode=user without User= setting
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2264404. Replaces #31356.
This commit is contained in:
parent
190ff0d0a8
commit
d42b81f93f
@ -4451,6 +4451,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;
|
||||
@ -4459,7 +4469,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
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user