Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/inetd inetd: prepare for lint's strict bool mode



details:   https://anonhg.NetBSD.org/src/rev/9723dacd983b
branches:  trunk
changeset: 985659:9723dacd983b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Sep 03 20:24:28 2021 +0000

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

diffstat:

 usr.sbin/inetd/Makefile   |    3 +-
 usr.sbin/inetd/inetd.c    |  156 ++++++++++++++++++++++-----------------------
 usr.sbin/inetd/inetd.h    |    5 +-
 usr.sbin/inetd/ipsec.c    |   13 ++-
 usr.sbin/inetd/parse_v2.c |   16 ++--
 5 files changed, 97 insertions(+), 96 deletions(-)

diffs (truncated from 724 to 300 lines):

diff -r 5fbdc4874b5d -r 9723dacd983b usr.sbin/inetd/Makefile
--- a/usr.sbin/inetd/Makefile   Fri Sep 03 19:33:51 2021 +0000
+++ b/usr.sbin/inetd/Makefile   Fri Sep 03 20:24:28 2021 +0000
@@ -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 @@
 MAN=   inetd.8
 MLINKS=        inetd.8 inetd.conf.5
 WARNS= 6
+#LINTFLAGS+=   -T
 
 # Enables debug printouts when in debug mode
 CPPFLAGS+=-DDEBUG_ENABLE
diff -r 5fbdc4874b5d -r 9723dacd983b usr.sbin/inetd/inetd.c
--- a/usr.sbin/inetd/inetd.c    Fri Sep 03 19:33:51 2021 +0000
+++ b/usr.sbin/inetd/inetd.c    Fri Sep 03 20:24:28 2021 +0000
@@ -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 @@
 #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 @@
                                        /* 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 @@
                                           )) != -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 @@
                struct servtab  *sep;
 
                if (reload) {
-                       reload = 0;
+                       reload = false;
                        config_root();
                }
 
@@ -469,7 +469,7 @@
                                        goaway();
                                        break;
                                case SIGHUP:
-                                       reload = 1;
+                                       reload = true;
                                        break;
                                }
                                continue;
@@ -481,7 +481,7 @@
                        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 @@
 
        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 @@
                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 @@
                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 @@
 #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 @@
                                    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 @@
        }
 #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 @@
                            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 @@
                                    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 @@
                                    "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 @@
                        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 @@
                        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 @@
                                            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 @@
                                                    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 @@
 {
        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 @@
                (void) close(sep->se_fd);
                sep->se_fd = -1;
                if (!timingout) {
-                       timingout = 1;
+                       timingout = true;
                        alarm(RETRYTIME);
                }
                return;
@@ -1109,7 +1109,7 @@
                    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(""));



Home | Main Index | Thread Index | Old Index