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
+4 -5
View File
@@ -988,15 +988,14 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
else if (streq(opts.arg, "self"))
arg_uid = getuid();
else {
const char *name = opts.arg;
r = get_user_creds(
&name,
opts.arg,
/* flags= */ 0,
/* ret_username= */ NULL,
&arg_uid,
/* ret_gid= */ NULL,
/* ret_home= */ NULL,
/* ret_shell= */ NULL,
/* flags= */ 0);
/* ret_shell= */ NULL);
if (r < 0)
return log_error_errno(r, "Failed to resolve user '%s': %s",
opts.arg, STRERROR_USER(r));