inetd: prefer strtonum(3) to strspn(3)+atoi(3), NFC

strtonum(3) does effectively the same validation as we had, but it's more
concise.
This commit is contained in:
Kyle Evans 2019-12-31 04:36:14 +00:00
parent 8acd3f126a
commit 1c3b9acf2e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356217

View File

@ -649,8 +649,14 @@ ident_stream(int s, struct servtab *sep)
goto fakeid_fail;
if (!Fflag) {
if (iflag) {
if (p[strspn(p, "0123456789")] == '\0' &&
getpwuid(atoi(p)) != NULL)
const char *errstr;
uid_t uid;
uid = strtonum(p, 0, UID_MAX, &errstr);
if (errstr != NULL)
goto fakeid_fail;
if (getpwuid(uid) != NULL)
goto fakeid_fail;
} else {
if (getpwnam(p) != NULL)