Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Dec 2019 04:36:14 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r356217 - head/usr.sbin/inetd
Message-ID:  <201912310436.xBV4aFSH034616@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Tue Dec 31 04:36:14 2019
New Revision: 356217
URL: https://svnweb.freebsd.org/changeset/base/356217

Log:
  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.

Modified:
  head/usr.sbin/inetd/builtins.c

Modified: head/usr.sbin/inetd/builtins.c
==============================================================================
--- head/usr.sbin/inetd/builtins.c	Tue Dec 31 04:16:52 2019	(r356216)
+++ head/usr.sbin/inetd/builtins.c	Tue Dec 31 04:36:14 2019	(r356217)
@@ -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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912310436.xBV4aFSH034616>