From 79f1521b0e628be72bed3a648f0ae90b62fc69b8 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 2 Jan 2024 13:57:29 -0500 Subject: pwcache: Fix uninitialized pointers on OpenBSD POSIX specifies that the get{pw,gr}*_r() functions store a NULL pointer to *result on error. However, OpenBSD does not always do this[1][2]: > if (bufsize < GETGR_R_SIZE_MAX) > return ERANGE; Work around it by explicitly initializing ret to NULL. [1]: https://github.com/openbsd/src/blob/e4829a9cc666f01ca5062d7fc15c20ab2d69229e/lib/libc/gen/getgrent.c#L135-L136 [2]: https://github.com/openbsd/src/blob/e4829a9cc666f01ca5062d7fc15c20ab2d69229e/lib/libc/gen/getgrent.c#L183-L184 --- src/pwcache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/pwcache.c') diff --git a/src/pwcache.c b/src/pwcache.c index c728ba9..79437d8 100644 --- a/src/pwcache.c +++ b/src/pwcache.c @@ -90,7 +90,7 @@ struct bfs_users *bfs_users_new(void) { static void *bfs_getpwnam_impl(const void *key, void *ptr, size_t bufsize) { struct bfs_passwd *storage = ptr; - struct passwd *ret; + struct passwd *ret = NULL; errno = getpwnam_r(key, &storage->pwd, storage->buf, bufsize, &ret); return ret; } @@ -109,7 +109,7 @@ static void *bfs_getpwuid_impl(const void *key, void *ptr, size_t bufsize) { const uid_t *uid = key; struct bfs_passwd *storage = ptr; - struct passwd *ret; + struct passwd *ret = NULL; errno = getpwuid_r(*uid, &storage->pwd, storage->buf, bufsize, &ret); return ret; } @@ -171,7 +171,7 @@ struct bfs_groups *bfs_groups_new(void) { static void *bfs_getgrnam_impl(const void *key, void *ptr, size_t bufsize) { struct bfs_group *storage = ptr; - struct group *ret; + struct group *ret = NULL; errno = getgrnam_r(key, &storage->grp, storage->buf, bufsize, &ret); return ret; } @@ -190,7 +190,7 @@ static void *bfs_getgrgid_impl(const void *key, void *ptr, size_t bufsize) { const gid_t *gid = key; struct bfs_group *storage = ptr; - struct group *ret; + struct group *ret = NULL; errno = getgrgid_r(*gid, &storage->grp, storage->buf, bufsize, &ret); return ret; } -- cgit v1.2.3