about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-10-10 20:04:18 -0400
committerRich Felker <dalias@aerifal.cx>2020-10-14 20:27:12 -0400
commitda845d52c5a8bee206fae899654e393d725a287f (patch)
treeef1471628b81efed33e5ac0c862226095eb1d0a8 /src
parentb7bc966522d73e1dc420b5ee6fc7a2e78099a08c (diff)
downloadmusl-da845d52c5a8bee206fae899654e393d725a287f.tar.gz
musl-da845d52c5a8bee206fae899654e393d725a287f.tar.xz
musl-da845d52c5a8bee206fae899654e393d725a287f.zip
fix getgrouplist when nscd reports an empty list
commit 500c6886c654fd45e4926990fee2c61d816be197 broke this by fixing
the behavior of fread to conform to the C standard; getgroupslist was
assuming the old behavior, that a request to read 1 member of length 0
would return 1, not 0.
Diffstat (limited to 'src')
-rw-r--r--src/passwd/getgrouplist.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/passwd/getgrouplist.c b/src/passwd/getgrouplist.c
index 43e51824..301824ce 100644
--- a/src/passwd/getgrouplist.c
+++ b/src/passwd/getgrouplist.c
@@ -31,7 +31,8 @@ int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
 	if (resp[INITGRFOUND]) {
 		nscdbuf = calloc(resp[INITGRNGRPS], sizeof(uint32_t));
 		if (!nscdbuf) goto cleanup;
-		if (!fread(nscdbuf, sizeof(*nscdbuf)*resp[INITGRNGRPS], 1, f)) {
+		size_t nbytes = sizeof(*nscdbuf)*resp[INITGRNGRPS];
+		if (nbytes && !fread(nscdbuf, nbytes, 1, f)) {
 			if (!ferror(f)) errno = EIO;
 			goto cleanup;
 		}