Module Name:    src
Committed By:   rillig
Date:           Fri Sep  3 20:24:28 UTC 2021

Modified Files:
        src/usr.sbin/inetd: Makefile inetd.c inetd.h ipsec.c parse_v2.c

Log Message:
inetd: prepare for lint's strict bool mode

Lint's strict bool mode considers bool incompatible with the other
scalar types.  This makes the type of expressions more visible in the
code.  In particular, conditions of the form '!strcmp(...)' are no
longer allowed, they have to be written as 'strcmp(...) == 0'.

The operator '!' cannot be used with sep->se_wait since that has type
pid_t, not bool.

No change to the resulting binary.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.sbin/inetd/Makefile
cvs rdiff -u -r1.133 -r1.134 src/usr.sbin/inetd/inetd.c
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/inetd/inetd.h
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/inetd/ipsec.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/inetd/parse_v2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/inetd/Makefile
diff -u src/usr.sbin/inetd/Makefile:1.28 src/usr.sbin/inetd/Makefile:1.29
--- src/usr.sbin/inetd/Makefile:1.28	Mon Aug 30 18:21:11 2021
+++ src/usr.sbin/inetd/Makefile	Fri Sep  3 20:24:28 2021
@@ -1,5 +1,5 @@
 #	from: @(#)Makefile	8.1 (Berkeley) 6/6/93
-#	$NetBSD: Makefile,v 1.28 2021/08/30 18:21:11 rillig Exp $
+#	$NetBSD: Makefile,v 1.29 2021/09/03 20:24:28 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -10,6 +10,7 @@ SRCS=	inetd.c parse_v2.c
 MAN=	inetd.8
 MLINKS=	inetd.8 inetd.conf.5
 WARNS=	6
+#LINTFLAGS+=	-T
 
 # Enables debug printouts when in debug mode
 CPPFLAGS+=-DDEBUG_ENABLE

Index: src/usr.sbin/inetd/inetd.c
diff -u src/usr.sbin/inetd/inetd.c:1.133 src/usr.sbin/inetd/inetd.c:1.134
--- src/usr.sbin/inetd/inetd.c:1.133	Fri Sep  3 19:33:51 2021
+++ src/usr.sbin/inetd/inetd.c	Fri Sep  3 20:24:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: inetd.c,v 1.133 2021/09/03 19:33:51 rillig Exp $	*/
+/*	$NetBSD: inetd.c,v 1.134 2021/09/03 20:24:28 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)inetd.c	8.4 (Berkeley) 4/13/94";
 #else
-__RCSID("$NetBSD: inetd.c,v 1.133 2021/09/03 19:33:51 rillig Exp $");
+__RCSID("$NetBSD: inetd.c,v 1.134 2021/09/03 20:24:28 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -337,28 +337,28 @@ struct biltin {
 					/* function which performs it */
 } biltins[] = {
 	/* Echo received data */
-	{ "echo",	SOCK_STREAM,	1, 0,	echo_stream },
-	{ "echo",	SOCK_DGRAM,	0, 0,	echo_dg },
+	{ "echo",	SOCK_STREAM,	true, false,	echo_stream },
+	{ "echo",	SOCK_DGRAM,	false, false,	echo_dg },
 
 	/* Internet /dev/null */
-	{ "discard",	SOCK_STREAM,	1, 0,	discard_stream },
-	{ "discard",	SOCK_DGRAM,	0, 0,	discard_dg },
+	{ "discard",	SOCK_STREAM,	true, false,	discard_stream },
+	{ "discard",	SOCK_DGRAM,	false, false,	discard_dg },
 
 	/* Return 32 bit time since 1970 */
-	{ "time",	SOCK_STREAM,	0, 0,	machtime_stream },
-	{ "time",	SOCK_DGRAM,	0, 0,	machtime_dg },
+	{ "time",	SOCK_STREAM,	false, false,	machtime_stream },
+	{ "time",	SOCK_DGRAM,	false, false,	machtime_dg },
 
 	/* Return human-readable time */
-	{ "daytime",	SOCK_STREAM,	0, 0,	daytime_stream },
-	{ "daytime",	SOCK_DGRAM,	0, 0,	daytime_dg },
+	{ "daytime",	SOCK_STREAM,	false, false,	daytime_stream },
+	{ "daytime",	SOCK_DGRAM,	false, false,	daytime_dg },
 
 	/* Familiar character generator */
-	{ "chargen",	SOCK_STREAM,	1, 0,	chargen_stream },
-	{ "chargen",	SOCK_DGRAM,	0, 0,	chargen_dg },
+	{ "chargen",	SOCK_STREAM,	true, false,	chargen_stream },
+	{ "chargen",	SOCK_DGRAM,	false, false,	chargen_dg },
 
-	{ "tcpmux",	SOCK_STREAM,	1, 0,	tcpmux },
+	{ "tcpmux",	SOCK_STREAM,	true, false,	tcpmux },
 
-	{ NULL, 0, 0, 0, NULL }
+	{ NULL, 0, false, false, NULL }
 };
 
 /* list of "bad" ports. I.e. ports that are most obviously used for
@@ -389,12 +389,12 @@ main(int argc, char *argv[])
 					   )) != -1)
 		switch(ch) {
 		case 'd':
-			debug = 1;
+			debug = true;
 			options |= SO_DEBUG;
 			break;
 #ifdef LIBWRAP
 		case 'l':
-			lflag = 1;
+			lflag = true;
 			break;
 #endif
 		case '?':
@@ -448,7 +448,7 @@ main(int argc, char *argv[])
 		struct servtab	*sep;
 
 		if (reload) {
-			reload = 0;
+			reload = false;
 			config_root();
 		}
 
@@ -469,7 +469,7 @@ main(int argc, char *argv[])
 					goaway();
 					break;
 				case SIGHUP:
-					reload = 1;
+					reload = true;
 					break;
 				}
 				continue;
@@ -481,7 +481,7 @@ main(int argc, char *argv[])
 			if ((int)ev->ident != sep->se_fd)
 				continue;
 			DPRINTF(SERV_FMT ": service requested" , SERV_PARAMS(sep));
-			if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
+			if (sep->se_wait == 0 && sep->se_socktype == SOCK_STREAM) {
 				/* XXX here do the libwrap check-before-accept*/
 				ctrl = accept(sep->se_fd, NULL, NULL);
 				DPRINTF(SERV_FMT ": accept, ctrl fd %d",
@@ -508,9 +508,9 @@ spawn(struct servtab *sep, int ctrl)
 
 	pid = 0;
 #ifdef LIBWRAP_INTERNAL
-	dofork = 1;
+	dofork = true;
 #else
-	dofork = (sep->se_bi == 0 || sep->se_bi->bi_fork);
+	dofork = (sep->se_bi == NULL || sep->se_bi->bi_fork);
 #endif
 	if (dofork) {
 		if (rl_process(sep, ctrl)) {
@@ -519,12 +519,12 @@ spawn(struct servtab *sep, int ctrl)
 		pid = fork();
 		if (pid < 0) {
 			syslog(LOG_ERR, "fork: %m");
-			if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
+			if (sep->se_wait == 0 && sep->se_socktype == SOCK_STREAM)
 				close(ctrl);
 			sleep(1);
 			return;
 		}
-		if (pid != 0 && sep->se_wait) {
+		if (pid != 0 && sep->se_wait != 0) {
 			struct kevent	*ev;
 
 			sep->se_wait = pid;
@@ -546,7 +546,7 @@ spawn(struct servtab *sep, int ctrl)
 		if (dofork)
 			exit(0);
 	}
-	if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
+	if (sep->se_wait == 0 && sep->se_socktype == SOCK_STREAM)
 		close(ctrl);
 }
 
@@ -568,11 +568,11 @@ run_service(int ctrl, struct servtab *se
 #ifndef LIBWRAP_INTERNAL
 	if (sep->se_bi == 0)
 #endif
-	if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
-		request_init(&req, RQ_DAEMON, sep->se_argv[0] ?
+	if (sep->se_wait == 0 && sep->se_socktype == SOCK_STREAM) {
+		request_init(&req, RQ_DAEMON, sep->se_argv[0] != NULL ?
 		    sep->se_argv[0] : sep->se_service, RQ_FILE, ctrl, NULL);
 		fromhost(&req);
-		denied = !hosts_access(&req);
+		denied = hosts_access(&req) == 0;
 		if (denied || lflag) {
 			if (getnameinfo(&sep->se_ctrladdr,
 			    (socklen_t)sep->se_ctrladdr.sa_len, NULL, 0,
@@ -582,7 +582,7 @@ run_service(int ctrl, struct servtab *se
 				    ntohs(sep->se_ctrladdr_in.sin_port));
 			}
 			service = buf;
-			if (req.client->sin) {
+			if (req.client->sin != NULL) {
 				sockaddr_snprintf(abuf, sizeof(abuf), "%a",
 				    req.client->sin);
 			} else {
@@ -603,9 +603,9 @@ run_service(int ctrl, struct servtab *se
 	}
 #endif /* LIBWRAP */
 
-	if (sep->se_bi) {
+	if (sep->se_bi != NULL) {
 		if (didfork) {
-			for (s = servtab; s; s = s->se_next)
+			for (s = servtab; s != NULL; s = s->se_next)
 				if (s->se_fd != -1 && s->se_fd != ctrl) {
 					close(s->se_fd);
 					s->se_fd = -1;
@@ -618,14 +618,14 @@ run_service(int ctrl, struct servtab *se
 			    sep->se_service, sep->se_proto, sep->se_user);
 			goto reject;
 		}
-		if (sep->se_group &&
+		if (sep->se_group != NULL &&
 		    (grp = getgrnam(sep->se_group)) == NULL) {
 			syslog(LOG_ERR, "%s/%s: %s: No such group",
 			    sep->se_service, sep->se_proto, sep->se_group);
 			goto reject;
 		}
-		if (pwd->pw_uid) {
-			if (sep->se_group)
+		if (pwd->pw_uid != 0) {
+			if (sep->se_group != NULL)
 				pwd->pw_gid = grp->gr_gid;
 			if (setgid(pwd->pw_gid) < 0) {
 				syslog(LOG_ERR,
@@ -641,7 +641,7 @@ run_service(int ctrl, struct servtab *se
 				    sep->se_proto, pwd->pw_uid);
 				goto reject;
 			}
-		} else if (sep->se_group) {
+		} else if (sep->se_group != NULL) {
 			(void) setgid((gid_t)grp->gr_gid);
 		}
 		DPRINTF("%d execl %s",
@@ -826,7 +826,7 @@ config(void)
 				    "supported by the kernel",
 				    sep->se_service, sep->se_proto,
 				    sep->se_hostaddr);
-				sep->se_checked = 0;
+				sep->se_checked = false;
 				continue;
 			}
 			close(s);
@@ -835,7 +835,7 @@ config(void)
 			hints.ai_family = sep->se_family;
 			hints.ai_socktype = sep->se_socktype;
 			hints.ai_flags = AI_PASSIVE;
-			if (!strcmp(sep->se_hostaddr, "*"))
+			if (strcmp(sep->se_hostaddr, "*") == 0)
 				host = NULL;
 			else
 				host = sep->se_hostaddr;
@@ -844,7 +844,7 @@ config(void)
 			else
 				port = sep->se_service;
 			error = getaddrinfo(host, port, &hints, &res);
-			if (error) {
+			if (error != 0) {
 				if (error == EAI_SERVICE) {
 					/* gai_strerror not friendly enough */
 					syslog(LOG_WARNING, SERV_FMT ": "
@@ -856,15 +856,15 @@ config(void)
 					    sep->se_hostaddr,
 					    gai_strerror(error));
 				}
-				sep->se_checked = 0;
+				sep->se_checked = false;
 				continue;
 			}
-			if (res->ai_next) {
+			if (res->ai_next != NULL) {
 				syslog(LOG_ERR,
 					SERV_FMT ": %s: resolved to multiple addr",
 				    SERV_PARAMS(sep),
 				    sep->se_hostaddr);
-				sep->se_checked = 0;
+				sep->se_checked = false;
 				freeaddrinfo(res);
 				continue;
 			}
@@ -889,7 +889,7 @@ config(void)
 						    SERV_FMT
 						    ": unknown service",
 						    SERV_PARAMS(sep));
-						sep->se_checked = 0;
+						sep->se_checked = false;
 						continue;
 					}
 					sep->se_rpcprog = rp->r_number;
@@ -917,7 +917,7 @@ retry(void)
 {
 	struct servtab *sep;
 
-	timingout = 0;
+	timingout = false;
 	for (sep = servtab; sep != NULL; sep = sep->se_next) {
 		if (sep->se_fd == -1 && !ISMUX(sep)) {
 			switch (sep->se_family) {
@@ -1036,7 +1036,7 @@ setsockopt(fd, SOL_SOCKET, opt, &on, (so
 		(void) close(sep->se_fd);
 		sep->se_fd = -1;
 		if (!timingout) {
-			timingout = 1;
+			timingout = true;
 			alarm(RETRYTIME);
 		}
 		return;
@@ -1109,7 +1109,7 @@ register_rpc(struct servtab *sep)
 		    sep->se_rpcprog, n, nconf->nc_netid,
 		    taddr2uaddr(nconf, &nbuf));
 		(void)rpcb_unset((unsigned int)sep->se_rpcprog, (unsigned int)n, nconf);
-		if (!rpcb_set((unsigned int)sep->se_rpcprog, (unsigned int)n, nconf, &nbuf))
+		if (rpcb_set((unsigned int)sep->se_rpcprog, (unsigned int)n, nconf, &nbuf) == 0)
 			syslog(LOG_ERR, "rpcb_set: %u %d %s %s%s",
 			    sep->se_rpcprog, n, nconf->nc_netid,
 			    taddr2uaddr(nconf, &nbuf), clnt_spcreateerror(""));
@@ -1133,7 +1133,7 @@ unregister_rpc(struct servtab *sep)
 	for (n = sep->se_rpcversl; n <= sep->se_rpcversh; n++) {
 		DPRINTF("rpcb_unset(%u, %d, %s)",
 		    sep->se_rpcprog, n, nconf->nc_netid);
-		if (!rpcb_unset((unsigned int)sep->se_rpcprog, (unsigned int)n, nconf))
+		if (rpcb_unset((unsigned int)sep->se_rpcprog, (unsigned int)n, nconf) == 0)
 			syslog(LOG_ERR, "rpcb_unset(%u, %d, %s) failed\n",
 			    sep->se_rpcprog, n, nconf->nc_netid);
 	}
@@ -1289,7 +1289,7 @@ more:
 
 	/* Check for a host name. */
 	hostdelim = strrchr(arg, ':');
-	if (hostdelim) {
+	if (hostdelim != NULL) {
 		*hostdelim = '\0';
 		if (arg[0] == '[' && hostdelim > arg && hostdelim[-1] == ']') {
 			hostdelim[-1] = '\0';
@@ -1412,8 +1412,7 @@ do { \
 	    sep->se_service, (arg)); \
 	freeconfig(sep); \
 	goto more; \
-	/*NOTREACHED*/ \
-} while (/*CONSTCOND*/0)
+} while (false)
 
 #define	GETVAL(arg) \
 do { \
@@ -1434,8 +1433,7 @@ do { \
 		freeconfig(sep); \
 		goto more; \
 	} \
-	/*NOTREACHED*/ \
-} while (/*CONSTCOND*/0)
+} while (false)
 
 #define	ASSIGN(arg) \
 do { \
@@ -1445,7 +1443,7 @@ do { \
 		sep->se_rcvbuf = val; \
 	else \
 		MALFORMED((arg)); \
-} while (/*CONSTCOND*/0)
+} while (false)
 
 	/*
 	 * Extract the send and receive buffer sizes before parsing
@@ -1583,14 +1581,14 @@ do { \
 	}
 
 	argc = 0;
-	for (arg = skip(&cp); cp; arg = skip(&cp)) {
+	for (arg = skip(&cp); cp != NULL; arg = skip(&cp)) {
 		if (argc < MAXARGV)
 			sep->se_argv[argc++] = newstr(arg);
 	}
 	while (argc <= MAXARGV)
 		sep->se_argv[argc++] = NULL;
 #ifdef IPSEC
-	sep->se_policy = policy ? newstr(policy) : NULL;
+	sep->se_policy = policy != NULL ? newstr(policy) : NULL;
 #endif
 	/* getconfigent read a positional service def, move to next line */
 	*current_pos = nextline(fconfig);
@@ -1656,12 +1654,12 @@ again:
 	start = cp;
 	/* Parse shell-style quotes */
 	quote = '\0';
-	while (*cp && (quote || (*cp != ' ' && *cp != '\t'))) {
+	while (*cp != '\0' && (quote != '\0' || (*cp != ' ' && *cp != '\t'))) {
 		if (*cp == '\'' || *cp == '"') {
-			if (quote && *cp != quote)
+			if (quote != '\0' && *cp != quote)
 				cp++;
 			else {
-				if (quote)
+				if (quote != '\0')
 					quote = '\0';
 				else
 					quote = *cp;
@@ -1682,13 +1680,13 @@ nextline(FILE *fd)
 	char *cp;
 
 	if (fgets(line, (int)sizeof(line), fd) == NULL) {
-		if (ferror(fd)) {
+		if (ferror(fd) != 0) {
 			ERR("Error when reading next line: %s", strerror(errno));
 		}
 		return NULL;
 	}
 	cp = strchr(line, '\n');
-	if (cp)
+	if (cp != NULL)
 		*cp = '\0';
 	line_number++;
 	return line;
@@ -1837,7 +1835,7 @@ chargen_stream(int s, struct servtab *se
 
 	inetd_setproctitle(sep->se_service, s);
 
-	if (!endring) {
+	if (endring == NULL) {
 		initring();
 		rs = ring;
 	}
@@ -2006,7 +2004,7 @@ print_service(const char *action, struct
 		    sep->se_wait, sep->se_service_max, sep->se_user, sep->se_group,
 		    (long)sep->se_bi, sep->se_server
 #ifdef IPSEC
-		    , (sep->se_policy ? sep->se_policy : "")
+		    , (sep->se_policy != NULL ? sep->se_policy : "")
 #endif
 		    );
 	else
@@ -2022,7 +2020,7 @@ print_service(const char *action, struct
 		    sep->se_wait, sep->se_service_max, sep->se_user, sep->se_group,
 		    (long)sep->se_bi, sep->se_server
 #ifdef IPSEC
-		    , (sep->se_policy ? sep->se_policy : "")
+		    , (sep->se_policy != NULL ? sep->se_policy : "")
 #endif
 		    );
 }
@@ -2090,7 +2088,7 @@ tcpmux(int ctrl, struct servtab *sep)
 	 * Help is a required command, and lists available services,
 	 * one per line.
 	 */
-	if (!strcasecmp(service, "help")) {
+	if (strcasecmp(service, "help") == 0) {
 		strwrite(ctrl, "+Available services:\r\n");
 		strwrite(ctrl, "help\r\n");
 		for (sep = servtab; sep != NULL; sep = sep->se_next) {
@@ -2107,10 +2105,10 @@ tcpmux(int ctrl, struct servtab *sep)
 	for (sep = servtab; sep != NULL; sep = sep->se_next) {
 		if (!ISMUX(sep))
 			continue;
-		if (!strcasecmp(service, sep->se_service)) {
+		if (strcasecmp(service, sep->se_service) == 0) {
 			if (ISMUXPLUS(sep))
 				strwrite(ctrl, "+Go\r\n");
-			run_service(ctrl, sep, 1 /* forked */);
+			run_service(ctrl, sep, true /* forked */);
 			return;
 		}
 	}
@@ -2170,7 +2168,7 @@ port_good_dg(struct sockaddr *sa)
 #endif
 	default:
 		/* XXX unsupported af, is it safe to assume it to be safe? */
-		return (1);
+		return true;
 	}
 
 	for (i = 0; bad_ports[i] != 0; i++) {
@@ -2178,7 +2176,7 @@ port_good_dg(struct sockaddr *sa)
 			goto bad;
 	}
 
-	return (1);
+	return true;
 
 bad:
 	if (getnameinfo(sa, sa->sa_len, hbuf, (socklen_t)sizeof(hbuf), NULL, 0,
@@ -2186,7 +2184,7 @@ bad:
 		strlcpy(hbuf, "?", sizeof(hbuf));
 	syslog(LOG_WARNING,"Possible DoS attack from %s, Port %d",
 		hbuf, port);
-	return (0);
+	return false;
 }
 
 /* XXX need optimization */
@@ -2197,19 +2195,19 @@ dg_broadcast(struct in_addr *in)
 	struct sockaddr_in *sin;
 
 	if (getifaddrs(&ifap) < 0)
-		return (0);
-	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+		return false;
+	for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
 		if (ifa->ifa_addr->sa_family != AF_INET ||
 		    (ifa->ifa_flags & IFF_BROADCAST) == 0)
 			continue;
 		sin = (struct sockaddr_in *)(void *)ifa->ifa_broadaddr;
 		if (sin->sin_addr.s_addr == in->s_addr) {
 			freeifaddrs(ifap);
-			return (1);
+			return true;
 		}
 	}
 	freeifaddrs(ifap);
-	return (0);
+	return false;
 }
 
 static int
@@ -2245,7 +2243,7 @@ config_root(void)
 	struct servtab *sep;
 	/* Uncheck services */
 	for (sep = servtab; sep != NULL; sep = sep->se_next) {
-		sep->se_checked = 0;
+		sep->se_checked = false;
 	}
 	defhost = newstr("*");
 #ifdef IPSEC
@@ -2304,7 +2302,7 @@ parse_protocol(struct servtab *sep)
 		sep->se_family = AF_LOCAL;
 	} else {
 		val = (int)strlen(sep->se_proto);
-		if (!val) {
+		if (val == 0) {
 			ERR("%s: invalid protocol specified",
 			    sep->se_service);
 			return -1;
@@ -2414,7 +2412,7 @@ parse_accept_filter(char *arg, struct se
 	char *accf, *accf_arg;
 	/* one and only one accept filter */
 	accf = strchr(arg, ':');
-	if (!accf)
+	if (accf == NULL)
 		return;
 	if (accf != strrchr(arg, ':') || *(accf + 1) == '\0') {
 		/* more than one ||  nothing beyond */
@@ -2425,7 +2423,7 @@ parse_accept_filter(char *arg, struct se
 	accf++;			/* skip delimiter */
 	strlcpy(sep->se_accf.af_name, accf, sizeof(sep->se_accf.af_name));
 	accf_arg = strchr(accf, ',');
-	if (!accf_arg)		/* zero or one arg, no more */
+	if (accf_arg == NULL)	/* zero or one arg, no more */
 		return;
 
 	if (strrchr(accf, ',') != accf_arg) {
@@ -2579,7 +2577,7 @@ include_matched_path(char *glob_path)
 	struct stat sb;
 	char *tmp;
 
-	if (lstat(glob_path, &sb)) {
+	if (lstat(glob_path, &sb) != 0) {
 		ERR("Error calling stat on path '%s': %s", glob_path,
 		    strerror(errno));
 		return;
@@ -2731,7 +2729,7 @@ rl_process(struct servtab *sep, int ctrl
 			/* Close the server for 10 minutes */
 			close_sep(sep);
 			if (!timingout) {
-				timingout = 1;
+				timingout = true;
 				alarm(RETRYTIME);
 			}
 
@@ -2810,7 +2808,7 @@ rl_get_name(struct servtab *sep, int ctr
 	socklen_t len = sizeof(struct sockaddr_storage);
 	switch (sep->se_socktype) {
 	case SOCK_STREAM:
-		if (getpeername(ctrl, (struct sockaddr *)&addr, &len)) {
+		if (getpeername(ctrl, (struct sockaddr *)&addr, &len) != 0) {
 			/* error, log it and skip ip rate limiting */
 			syslog(LOG_ERR,
 				SERV_FMT " failed to get peer name of the "
@@ -2861,7 +2859,7 @@ static void
 rl_drop_connection(struct servtab *sep, int ctrl)
 {
 
-	if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
+	if (sep->se_wait == 0 && sep->se_socktype == SOCK_STREAM) {
 		/*
 		 * If the fd isn't a listen socket,
 		 * close the individual connection too.

Index: src/usr.sbin/inetd/inetd.h
diff -u src/usr.sbin/inetd/inetd.h:1.2 src/usr.sbin/inetd/inetd.h:1.3
--- src/usr.sbin/inetd/inetd.h:1.2	Mon Aug 30 17:32:23 2021
+++ src/usr.sbin/inetd/inetd.h	Fri Sep  3 20:24:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: inetd.h,v 1.2 2021/08/30 17:32:23 rillig Exp $	*/
+/*	$NetBSD: inetd.h,v 1.3 2021/09/03 20:24:28 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
@@ -70,6 +70,7 @@
 #include <arpa/inet.h>
 
 #include <netdb.h>
+#include <stdbool.h>
 
 #include "pathnames.h"
 
@@ -109,7 +110,7 @@ typedef enum service_type {
 	if (debug) {\
 		fprintf(stderr, fmt "\n" __VA_OPT__(,) __VA_ARGS__);\
 	}\
-} while (0)
+} while (false)
 #else
 #define DPRINTF(fmt, ...) __nothing
 #endif

Index: src/usr.sbin/inetd/ipsec.c
diff -u src/usr.sbin/inetd/ipsec.c:1.6 src/usr.sbin/inetd/ipsec.c:1.7
--- src/usr.sbin/inetd/ipsec.c:1.6	Mon Aug 30 17:32:23 2021
+++ src/usr.sbin/inetd/ipsec.c	Fri Sep  3 20:24:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec.c,v 1.6 2021/08/30 17:32:23 rillig Exp $	*/
+/*	$NetBSD: ipsec.c,v 1.7 2021/09/03 20:24:28 rillig Exp $	*/
 
 /*
  * Copyright (C) 1999 WIDE Project.
@@ -36,6 +36,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -58,7 +59,7 @@ ipsecsetup(int af, int fd, const char *p
 	char *p0, *p;
 	int error;
 
-	if (!policy || *policy == '\0')
+	if (policy == NULL || *policy == '\0')
 		p0 = p = strdup("in entrust; out entrust");
 	else
 		p0 = p = strdup(policy);
@@ -70,11 +71,11 @@ ipsecsetup(int af, int fd, const char *p
 			break;
 		while (*p && isspace((unsigned char)*p))
 			p++;
-		if (!*p) {
+		if (*p == '\0') {
 			p = NULL;
 			continue;
 		}
-		error = ipsecsetup0(af, fd, p, 1);
+		error = ipsecsetup0(af, fd, p, true);
 		if (error < 0)
 			break;
 		p = NULL;
@@ -91,7 +92,7 @@ ipsecsetup_test(const char *policy)
 	char *buf;
 	int error;
 
-	if (!policy)
+	if (policy == NULL)
 		return -1;
 	p0 = p = strdup(policy);
 	if (p == NULL)
@@ -104,7 +105,7 @@ ipsecsetup_test(const char *policy)
 			break;
 		while (*p && isspace((unsigned char)*p))
 			p++;
-		if (!*p) {
+		if (*p == '\0') {
 			p = NULL;
 			continue;
 		}

Index: src/usr.sbin/inetd/parse_v2.c
diff -u src/usr.sbin/inetd/parse_v2.c:1.4 src/usr.sbin/inetd/parse_v2.c:1.5
--- src/usr.sbin/inetd/parse_v2.c:1.4	Mon Aug 30 18:21:11 2021
+++ src/usr.sbin/inetd/parse_v2.c	Fri Sep  3 20:24:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse_v2.c,v 1.4 2021/08/30 18:21:11 rillig Exp $	*/
+/*	$NetBSD: parse_v2.c,v 1.5 2021/09/03 20:24:28 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: parse_v2.c,v 1.4 2021/08/30 18:21:11 rillig Exp $");
+__RCSID("$NetBSD: parse_v2.c,v 1.5 2021/09/03 20:24:28 rillig Exp $");
 
 #include <ctype.h>
 #include <errno.h>
@@ -392,7 +392,7 @@ parse_quotes(char **cpp)
 	char quote = *cp;
 
 	strmove(cp, 1);
-	while (*cp && quote) {
+	while (*cp != '\0' && quote != '\0') {
 		if (*cp == quote) {
 			quote = '\0';
 			strmove(cp, 1);
@@ -449,7 +449,7 @@ parse_quotes(char **cpp)
 		cp++;
 	}
 
-	if (*cp == '\0' && quote) {
+	if (*cp == '\0' && quote != '\0') {
 		ERR("Unclosed quote");
 		return false;
 	}
@@ -787,7 +787,7 @@ size_to_bytes(char *arg)
 
 	count = (int)strtoi(arg, &tail, 10, 0, INT_MAX, &rstatus);
 
-	if (rstatus && rstatus != ENOTSUP) {
+	if (rstatus != 0 && rstatus != ENOTSUP) {
 		ERR("Invalid buffer size '%s': %s", arg, strerror(rstatus));
 		return -1;
 	}
@@ -951,7 +951,7 @@ service_max_handler(struct servtab *sep,
 	size_t count = (size_t)strtou(count_str, NULL, 10, 0,
 	    SERVTAB_COUNT_MAX, &rstatus);
 
-	if (rstatus) {
+	if (rstatus != 0) {
 		ERR("Invalid service_max '%s': %s", count_str,
 		    strerror(rstatus));
 		return KEY_HANDLER_FAILURE;
@@ -988,7 +988,7 @@ ip_max_handler(struct servtab *sep, vlis
 	size_t count = (size_t)strtou(count_str, NULL, 10, 0,
 	    SERVTAB_COUNT_MAX, &rstatus);
 
-	if (rstatus) {
+	if (rstatus != 0) {
 		ERR("Invalid ip_max '%s': %s", count_str, strerror(rstatus));
 		return KEY_HANDLER_FAILURE;
 	}
@@ -1138,7 +1138,7 @@ ipsec_handler(struct servtab *sep, vlist
 	 * An empty string indicates that IPsec was disabled, handled in
 	 * fill_default_values.
 	 */
-	sep->se_policy = policy ? newstr(ipsecstr) : newstr("");
+	sep->se_policy = policy != NULL ? newstr(ipsecstr) : newstr("");
 
 	if (next_value(values) != NULL) {
 		TMA("ipsec");

Reply via email to