X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fpasswd%2Fgetspnam_r.c;h=541206fa14db8dcea55f26dc24e070c88583ac72;hb=8cd738bbee3b4e60a99b71599c338bf444070f18;hp=15f8c87b7dfbaba74c984b08b729fd68f2170c26;hpb=b3646b30d670ac5a38674ecc492c38f7d4e92682;p=musl diff --git a/src/passwd/getspnam_r.c b/src/passwd/getspnam_r.c index 15f8c87b..541206fa 100644 --- a/src/passwd/getspnam_r.c +++ b/src/passwd/getspnam_r.c @@ -72,14 +72,15 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct /* Disallow potentially-malicious user names */ if (*name=='.' || strchr(name, '/') || !l) - return EINVAL; + return errno = EINVAL; /* Buffer size must at least be able to hold name, plus some.. */ - if (size < l+100) return ERANGE; + if (size < l+100) + return errno = ERANGE; /* Protect against truncation */ if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path) - return EINVAL; + return errno = EINVAL; fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC); if (fd >= 0) { @@ -98,7 +99,7 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct pthread_cleanup_push(cleanup, f); while (fgets(buf, size, f) && (k=strlen(buf))>0) { - if (skip || strncmp(name, buf, l)) { + if (skip || strncmp(name, buf, l) || buf[l]!=':') { skip = buf[k-1] != '\n'; continue; } @@ -112,5 +113,6 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct break; } pthread_cleanup_pop(1); + if (rv) errno = rv; return rv; }