瀏覽代碼

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.
Rich Felker 4 年之前
父節點
當前提交
da845d52c5
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. 2 1
      src/passwd/getgrouplist.c

+ 2 - 1
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;
 		}