]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
userdb: reset errno before getpwent() 36115/head
authorLennart Poettering <lennart@poettering.net>
Wed, 22 Jan 2025 15:44:12 +0000 (16:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 22 Jan 2025 16:41:12 +0000 (17:41 +0100)
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.

src/shared/userdb.c

index be7c77d950321a6811fcf1f6c96933670df2e3e7..a1da514884d31e636cc1ec3ed91f9500414e6c60 100644 (file)
@@ -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;