From: Tobias Stoeckmann Date: Fri, 3 Apr 2026 13:58:40 +0000 (+0200) Subject: pwdutils: Set errno with out of range UIDs/GIDs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ad1da9bbc3eb9fc7952fe30514d4e0afa730fdc;p=thirdparty%2Futil-linux.git pwdutils: Set errno with out of range UIDs/GIDs 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 --- diff --git a/lib/pwdutils.c b/lib/pwdutils.c index 1c08eecc9..0a1c2e5bf 100644 --- a/lib/pwdutils.c +++ b/lib/pwdutils.c @@ -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;