about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2021-02-13 13:59:44 -0500
committerRich Felker <dalias@aerifal.cx>2021-02-13 13:59:44 -0500
commitcc577d0e058b53df5c0fe2ac17890a41d77e94c5 (patch)
tree9650c2a8b5dd5ebc415f724b4a1949dd32b26ffe
parenta75283d777ed1827ed247dbb465818a0ce371c8f (diff)
downloadmusl-cc577d0e058b53df5c0fe2ac17890a41d77e94c5.tar.gz
musl-cc577d0e058b53df5c0fe2ac17890a41d77e94c5.tar.xz
musl-cc577d0e058b53df5c0fe2ac17890a41d77e94c5.zip
fix misuse of getpwuid_r in cuserid
getpwuid_r can return 0 but without a result in the case where there
was no error but no record exists. in that case cuserid was treating
it as success and copying junk out of pw.pw_name to the output buffer.
-rw-r--r--src/legacy/cuserid.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/legacy/cuserid.c b/src/legacy/cuserid.c
index 3ff115a1..07866acf 100644
--- a/src/legacy/cuserid.c
+++ b/src/legacy/cuserid.c
@@ -9,7 +9,8 @@ char *cuserid(char *buf)
 	static char usridbuf[L_cuserid];
 	struct passwd pw, *ppw;
 	long pwb[256];
-	if (getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw))
+	getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
+	if (!ppw)
 		return 0;
 	size_t len = strnlen(pw.pw_name, L_cuserid);
 	if (len == L_cuserid)