user-util: return malloc'ed strings in get_user_creds

get_user_creds would use getpwnam() and then returns strings pointing
into the static buffer. This seems very iffy. Let's duplicate the
strings properly
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-05-21 18:02:05 +02:00
parent 3ecd6b69cf
commit c83ff0e58d
21 changed files with 176 additions and 203 deletions
+1 -2
View File
@@ -396,8 +396,7 @@ static int condition_test_user(Condition *c, char **env) {
if (streq(username, c->parameter))
return 1;
const char *u = c->parameter;
r = get_user_creds(&u, &id, NULL, NULL, NULL, USER_CREDS_ALLOW_MISSING);
r = get_user_creds(c->parameter, USER_CREDS_ALLOW_MISSING, NULL, &id, NULL, NULL, NULL);
if (r < 0)
return 0;
+1 -3
View File
@@ -1704,9 +1704,7 @@ static int add_matches_for_coredump_uid(sd_journal *j, MatchUnitFlag flags, cons
return 0;
if (cached_uid == 0) {
const char *user = "systemd-coredump";
r = get_user_creds(&user, &cached_uid, NULL, NULL, NULL, 0);
r = get_user_creds("systemd-coredump", /* flags= */ 0, NULL, &cached_uid, NULL, NULL, NULL);
if (r < 0) {
log_debug_errno(r, "Failed to resolve systemd-coredump user, ignoring: %m");
cached_uid = UID_INVALID;