mirror of
git://git.musl-libc.org/musl
synced 2024-12-24 07:32:49 +00:00
set errno when getpw*_r, getgr*_r, and getspnam_r fail
these functions return an error code, and are not explicitly documented to set errno, but they are nonstandard and the historical implementations do set errno as well, and some applications expect this behavior. do likewise for compatibility. patch by Rudolph Pereira.
This commit is contained in:
parent
5c10c33d2a
commit
2d7d05f031
@ -34,6 +34,7 @@ static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, siz
|
||||
free(mem);
|
||||
free(line);
|
||||
pthread_setcancelstate(cs, 0);
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, si
|
||||
}
|
||||
free(line);
|
||||
pthread_setcancelstate(cs, 0);
|
||||
if (rv) errno = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -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 = EINVAL;
|
||||
|
||||
/* 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) {
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user