]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
userdb: reset errno before getpwent()
authorLennart Poettering <lennart@poettering.net>
Wed, 22 Jan 2025 15:44:12 +0000 (16:44 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 8 Feb 2025 06:51:06 +0000 (15:51 +0900)
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.

(cherry picked from commit 83e3b96d0a3b665b7b7a291500fa354a7760a917)

src/shared/userdb.c

index ff83d4bf902683e0eef6ae2ebc1e884d07c111de..29acebae19a468d95870df2a40c2af5e19760a8d 100644 (file)
@@ -773,6 +773,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;