mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
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.
This commit is contained in:
parent
a75283d777
commit
cc577d0e05
1 changed files with 2 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue