From 5ad1da9bbc3eb9fc7952fe30514d4e0afa730fdc Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 3 Apr 2026 15:58:40 +0200 Subject: [PATCH] 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 --- lib/pwdutils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; -- 2.47.3