From: Zbigniew Jędrzejewski-Szmek Date: Mon, 22 Jun 2026 18:19:25 +0000 (+0200) Subject: shared/creds-util: use getpwuid_malloc() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50b4f1e3bf55059f484bea537e93ad2b4bce151a;p=thirdparty%2Fsystemd.git shared/creds-util: use getpwuid_malloc() Static linking, i.e. without dlopen, sometimes fails when getpwuid is used. I doesn't fail in all cases (glibc version?), so I didn't do this initially. --- diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index 739973aa461..a15fcfc6b24 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -768,6 +768,7 @@ static int mangle_uid_into_key( uid_t uid, uint8_t md[static SHA256_DIGEST_LENGTH]) { + _cleanup_free_ struct passwd *pw = NULL; sd_id128_t mid; int r; @@ -778,12 +779,9 @@ static int mangle_uid_into_key( * (specifically, UID, user name, machine ID) with the key we'd otherwise use for system credentials, * and use the resulting hash as actual encryption key. */ - errno = 0; - struct passwd *pw = getpwuid(uid); - if (!pw) - return log_error_errno( - IN_SET(errno, 0, ENOENT) ? SYNTHETIC_ERRNO(ESRCH) : errno, - "Failed to resolve UID " UID_FMT ": %m", uid); + r = getpwuid_malloc(uid, &pw); + if (r < 0) + return log_error_errno(r, "Failed to resolve UID "UID_FMT": %m", uid); r = sd_id128_get_machine(&mid); if (r < 0)