iconv: fix missing bounds checking for shift_jis decoding
[musl.git] / src / legacy / cuserid.c
blobdcaf73d4e64882e857fa3f1ef5192af0e4bf6b16
1 #define _GNU_SOURCE
2 #include <pwd.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <string.h>
7 char *cuserid(char *buf)
9 static char usridbuf[L_cuserid];
10 struct passwd pw, *ppw;
11 long pwb[256];
12 if (buf) *buf = 0;
13 getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
14 if (!ppw)
15 return buf;
16 size_t len = strnlen(pw.pw_name, L_cuserid);
17 if (len == L_cuserid)
18 return buf;
19 if (!buf) buf = usridbuf;
20 memcpy(buf, pw.pw_name, len+1);
21 return buf;