]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/creds-util: use getpwuid_malloc()
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Mon, 22 Jun 2026 18:19:25 +0000 (20:19 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 2 Jul 2026 15:19:18 +0000 (17:19 +0200)
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.

src/shared/creds-util.c

index 739973aa46130f9b8811472f03a17841a5cb3811..a15fcfc6b245dd006fcdfb5fbea7686120800d77 100644 (file)
@@ -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)