From: Lennart Poettering Date: Wed, 22 Jan 2025 15:44:12 +0000 (+0100) Subject: userdb: reset errno before getpwent() X-Git-Tag: v258-rc1~1531^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F36115%2Fhead;p=thirdparty%2Fsystemd.git userdb: reset errno before getpwent() errno handling for NSS is always a bit weird since NSS modules generally are not particularly careful with it. Hence let's initialize errno explicitly before we invoke getpwent() so that we know it's in a reasonable state afterwards on failure, or zero if not. We do this in most places we use NSS, including in userdb when it comes to getgrent(), just for getpwent() we don't so far. Address that. --- diff --git a/src/shared/userdb.c b/src/shared/userdb.c index be7c77d9503..a1da514884d 100644 --- a/src/shared/userdb.c +++ b/src/shared/userdb.c @@ -853,6 +853,7 @@ int userdb_iterator_get(UserDBIterator *iterator, UserRecord **ret) { /* If NSS isn't covered elsewhere, let's iterate through it first, since it probably contains * the more traditional sources, which are probably good to show first. */ + errno = 0; pw = getpwent(); if (pw) { _cleanup_free_ char *buffer = NULL;