]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
pwdutils: Set errno with out of range UIDs/GIDs
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 3 Apr 2026 13:58:40 +0000 (15:58 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 3 Apr 2026 14:36:49 +0000 (16:36 +0200)
If a UID/GID is larger than its respective data type allows (but smaller
than uint64_t), then tools like newgrp erroneously assume that the user
or group simply does not exist.

Set errno to indicate that the supplied UID/GID is out of range instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
lib/pwdutils.c

index 1c08eecc9b604f5ced0b5f5f1182f30d030f76b9..0a1c2e5bf9e4d04086c5589386edf83f645b0bf5 100644 (file)
@@ -186,8 +186,10 @@ struct group *ul_getgrp_str(const char *str, gid_t *result)
                         *result = gr->gr_gid;
                 return gr;
         }
-        if (num > MAX_OF_UINT_TYPE(gid_t))
+        if (num > MAX_OF_UINT_TYPE(gid_t)) {
+                errno = ERANGE;
                 return NULL;
+        }
 
         if (result)
                 *result = (gid_t) num;
@@ -219,8 +221,10 @@ struct passwd *ul_getuserpw_str(const char *str, uid_t *result)
                         *result = pw->pw_uid;
                 return pw;
         }
-        if (num > MAX_OF_UINT_TYPE(uid_t))
+        if (num > MAX_OF_UINT_TYPE(uid_t)) {
+                errno = ERANGE;
                 return NULL;
+        }
 
         if (result)
                 *result = (uid_t) num;