X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Flegacy%2Fcuserid.c;h=dcaf73d4e64882e857fa3f1ef5192af0e4bf6b16;hb=760f5d7efed4d4761875334f8c4e6398be308cc9;hp=fd7832e41fdf15509a80583e8f7bb10473e53356;hpb=ef137da6428c342baabd3bcf9b5e91f75acefa64;p=musl diff --git a/src/legacy/cuserid.c b/src/legacy/cuserid.c index fd7832e4..dcaf73d4 100644 --- a/src/legacy/cuserid.c +++ b/src/legacy/cuserid.c @@ -2,15 +2,21 @@ #include #include #include +#include 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)) - return 0; + if (buf) *buf = 0; + getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw); + if (!ppw) + return buf; + size_t len = strnlen(pw.pw_name, L_cuserid); + if (len == L_cuserid) + return buf; if (!buf) buf = usridbuf; - snprintf(buf, L_cuserid, "%s", pw.pw_name); + memcpy(buf, pw.pw_name, len+1); return buf; }