summaryrefslogtreecommitdiffstats
path: root/src/pwcache.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-01-02 13:57:29 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-01-02 13:57:29 -0500
commit79f1521b0e628be72bed3a648f0ae90b62fc69b8 (patch)
tree839cd42577975f6b8707034ccecba917d4a49e33 /src/pwcache.c
parenteae90d86b5e3dda10f541dadcea6462587ff2bfc (diff)
downloadbfs-79f1521b0e628be72bed3a648f0ae90b62fc69b8.tar.xz
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
Diffstat (limited to 'src/pwcache.c')
-rw-r--r--src/pwcache.c8
1 files changed, 4 insertions, 4 deletions
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;
}