[Git][NTPsec/ntpsec][master] 8 commits: ntp.util: Ensure srcadr truthy before .startswith()

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Mon Jul 13 08:49:22 UTC 2026



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
b3341237 by James Browning at 2026-07-11T07:39:03-07:00
ntp.util: Ensure srcadr truthy before .startswith()

This prevents ntpq/ntmon from breaking on things like
NXDOMAIN from DNS and MDF_POOL associations.

- - - - -
cb9202c4 by Hal Murray at 2026-07-11T11:21:31-07:00
mode6: Skip addresses starting '\0' or '('

The former are empty string and the latter are unhandled.

- - - - -
1406b1af by Hal Murray at 2026-07-11T11:21:31-07:00
libntp: Don't resolve AF_UNSPEC like AF_INET

This also renders 000dfdcef and its' fallout moot.

- - - - -
2c347573 by James Browning at 2026-07-11T11:21:31-07:00
Docs: Remove extra address mode; revert 000dfdcef+ 1/x

- - - - -
b3b49b1f by James Browning at 2026-07-11T11:21:31-07:00
ntpmon: Remove extra address modes; revert 000dfdcef+ 2/x

- - - - -
bca0bdf7 by James Browning at 2026-07-11T11:21:31-07:00
Docs: Remove extra address mode; revert 000dfdcef+ 3/x

- - - - -
f745fec4 by James Browning at 2026-07-11T11:21:31-07:00
ntpq: Remove extra address mode; revert 000dfdcef+ 4/x

- - - - -
9beb8ad4 by James Browning at 2026-07-11T11:21:31-07:00
ntp.util: Remove extra address mode internals; revert 000dfdcef+ 5/x

- - - - -


7 changed files:

- docs/includes/ntpmon-body.adoc
- docs/includes/ntpq-body.adoc
- libntp/socktoa.c
- ntpclients/ntpmon.py
- ntpclients/ntpq.py
- ntpd/ntp_control.c
- pylib/util.py


Changes:

=====================================
docs/includes/ntpmon-body.adoc
=====================================
@@ -60,8 +60,7 @@ k:: Select previous peer (in select mode); arrow up also works.
 
 m:: Toggle MRUlist-only mode; suppresses peer display when on.
 
-n:: Toggle display of hostnames vs. IP addresses vs ntpd supplied names plus
-    IP addresses or ntpd supplied names and hostnames (default is hostnames).
+n:: Toggle display of hostnames vs. IP addresses (default is hostnames).
 
 o:: Change peer display to opeers mode, showing destination address.
 
@@ -102,10 +101,6 @@ x:: Cleanly terminate the program.
 
 -n:: Show IP addresses (vs. hostnames)
 
--s, --srcname:: Show srchost first then names and numbers
-
--S, --srcnumber:: Show srchost first then numbers
-
 -u:: Show units
 
 -V:: Display version and exit.


=====================================
docs/includes/ntpq-body.adoc
=====================================
@@ -79,12 +79,6 @@ read interactive format commands from the standard input.
   converting to the canonical host names.  You may get hostnames
   anyway for peers in the initialization phase before DNS has resolved
   the peer name.
-+-s+, +--srcname+::
-  Output host addresses by: Names passed to ntpd, then names reverse
-  resolved from addresses and finally, IP addresses themselves
-+-S+, +--srcnumber+::
-  Output host addresses by: Names passed to ntpd, then IP addresses
-  themselves 
 +-p+, +--peers+::
   Print a list of the peers known to the server as well as a summary of
   their state; this is equivalent to the +peers+ interactive command.


=====================================
libntp/socktoa.c
=====================================
@@ -46,7 +46,6 @@ socktoa_r(
 		switch(AF(sock)) {
 
 		case AF_INET:
-		case AF_UNSPEC:
 			inet_ntop(AF_INET, PSOCK_ADDR4(sock), buf, buflen);
 			break;
 


=====================================
ntpclients/ntpmon.py
=====================================
@@ -218,18 +218,17 @@ if __name__ == '__main__':
     ntp.util.stdversioncheck(bin_ver)
     try:
         (options, arguments) = getopt.getopt(sys.argv[1:],
-                                             "dD:hl:nsSuV",
+                                             "dD:hl:nuV",
                                              ["debug", "help", "logfile=",
                                               "numeric", "units",
-                                              "set-debug-level=", "version",
-                                              "srcname", "srcnumber"])
+                                              "set-debug-level=", "version"])
     except getopt.GetoptError as e:
         sys.stderr.write("%s\n" % e)
         sys.stderr.write(usage)
         raise SystemExit(1)
     progname = sys.argv[0]
 
-    showhostnames = 1
+    showhostnames = True
     wideremote = False
     showall = True
     showpeers = True
@@ -252,11 +251,7 @@ if __name__ == '__main__':
         elif switch in ("-l", "--logfile"):
             logname = val
         elif switch in ("-n", "--numeric"):
-            showhostnames = 0
-        elif switch in ("-s", "--srcname"):
-            showhostnames = 3
-        elif switch in ("-S", "--srcnumber"):
-            showhostnames = 2
+            showhostnames = False
         elif switch in ("-u", "--units"):
             showunits = True
         elif switch in ("-V", "--version"):
@@ -433,14 +428,8 @@ if __name__ == '__main__':
                         showpeers = not showpeers
                         detailmode = False  # detail + hide peers == crash
                     elif key == 'n':
-                        if peer_report.showhostnames == 2:
-                            peer_report.showhostnames = 0
-                        elif peer_report.showhostnames == 0:
-                            peer_report.showhostnames = 1
-                        elif peer_report.showhostnames == 1:
-                            peer_report.showhostnames = 3
-                        else:
-                            peer_report.showhostnames = 2
+                        peer_report.showhostnames = \
+                            not peer_report.showhostnames
                         mru_report.showhostnames = \
                             peer_report.showhostnames
                     elif key == 'o':


=====================================
ntpclients/ntpq.py
=====================================
@@ -84,7 +84,7 @@ class Ntpq(cmd.Cmd):
         #  so I am leaving them, and possibly duplicating them.
         self.rawmode = False            # Flag which indicates raw mode output.
         self.directmode = False         # Flag for direct MRU output.
-        self.showhostnames = 1          # If & 1, display names
+        self.showhostnames = True       # If False, display numeric IPs
         self.showunits = False          # If False, show old style float
         self.auth_delay = 20            # delay time (default 20msec)
         self.wideremote = False         # show wide remote names?
@@ -532,7 +532,7 @@ usage: timeout [ msec ]
                 value = queried[name][0]
                 rawvalue = queried[name][1]
                 if fmt in (NTP_ADD, NTP_ADP):
-                    if self.showhostnames & 1:  # if & 1, display names
+                    if self.showhostnames:  # if True, display names
                         if self.debug:
                             self.say("DNS lookup begins...")
                         value = ntp.util.canonicalize_dns(
@@ -665,29 +665,21 @@ usage: passwd []
         if not line:
             pass
         elif line == "yes":
-            self.showhostnames = 1
+            self.showhostnames = True
         elif line == "no":
-            self.showhostnames = 0
-        elif line == 'hostnum':
-            self.showhostnames = 2
-        elif line == 'hostname':
-            self.showhostnames = 3
+            self.showhostnames = False
         else:
             self.say("What?\n")
             pass
-        if self.showhostnames & 1:
-            self.say('resolved hostnames being shown\n')
+        if self.showhostnames:
+            self.say('hostnames being shown\n')
         else:
-            self.say('resolved hostnames not being shown\n')
-        if self.showhostnames & 2:
-            self.say('supplied hostnames being shown\n')
-        else:
-            self.say('supplied hostnames not being shown\n')
+            self.say('hostnames not being shown\n')
 
     def help_hostnames(self):
         self.say("""\
 function: specify whether hostnames or net numbers are printed
-usage: hostnames [yes|no|hostname|hostnum]
+usage: hostnames [yes|no]
 """)
 
     def do_debug(self, line):
@@ -1811,12 +1803,12 @@ if __name__ == '__main__':
     try:
         (options, arguments) = getopt.getopt(
             sys.argv[1:],
-            "46a:c:dD:hk:npsSVwW:ul:",
+            "46a:c:dD:hk:npVwW:ul:",
             ["ipv4", "ipv6", "authentication=",
              "command=", "debug", "set-debug-level=",
              "help", "keyfile", "numeric", "peers",
              "version", "wide", "width=", "units",
-             "logfile=", "srcname", "srcnumber"])
+             "logfile="])
     except getopt.GetoptError as e:
         sys.stderr.write("%s\n" % e)
         sys.stderr.write(usage)
@@ -1851,15 +1843,11 @@ if __name__ == '__main__':
             sys.stderr.write(usage)
             raise SystemExit(0)
         elif switch in ("-n", "--numeric"):
-            interpreter.showhostnames = 0
+            interpreter.showhostnames = False
         elif switch in ("-p", "--peers"):
             interpreter.ccmds.append("peers")
         elif switch in ("-k", "--keyfile"):
             keyfile = val
-        elif switch in ("-s", "--srcname"):
-            interpreter.showhostnames = 3
-        elif switch in ("-S", "--srcnumber"):
-            interpreter.showhostnames = 2
         elif switch in ("-V", "--version"):
             sys.stdout.write("ntpq %s\n" % version)
             raise SystemExit(0)


=====================================
ntpd/ntp_control.c
=====================================
@@ -1338,9 +1338,12 @@ ctl_putadr(
 		struct in_addr in4;
 		in4.s_addr = addr32;
 		cq = inet_ntoa(in4);
-	} else
+	} else {
 		cq = socktoa(addr);
-	ctl_putunqstr(tag, cq, strlen(cq));
+	}
+	if (('\0' != *cq) && ('(' != *cq)) {
+		ctl_putunqstr(tag, cq, strlen(cq));
+	}
 }
 
 


=====================================
pylib/util.py
=====================================
@@ -884,7 +884,7 @@ class PeerSummary:
                  debug=0, logfp=sys.stderr):
         self.displaymode = displaymode          # peers/apeers/opeers
         self.pktversion = pktversion            # interpretation of flash bits
-        self.showhostnames = showhostnames      # If false, display numeric IPs
+        self.showhostnames = showhostnames      # If False, display numeric IPs
         self.showunits = showunits              # If False show old style float
         self.wideremote = wideremote            # show wide remote names?
         self.debug = debug
@@ -1111,7 +1111,7 @@ class PeerSummary:
             ptype = 'b'
         elif hmode == ntp.magic.MODE_BROADCASTx:
             # broadcast or multicast server
-            if srcadr.startswith("224."):       # IANA multicast address prefix
+            if srcadr and srcadr.startswith("224."):  # IANA multicast address prefix
                 ptype = 'M'
             else:
                 ptype = 'B'
@@ -1120,7 +1120,7 @@ class PeerSummary:
                 ptype = 'l'     # local refclock
             elif dstadr_refid == "POOL":
                 ptype = 'p'     # pool
-            elif srcadr.startswith("224."):
+            elif srcadr and srcadr.startswith("224."):
                 ptype = 'a'     # manycastclient (compatibility with Classic)
             elif ntscookies > -1:
                 # FIXME: Will foo up if there are ever more than 9 cookies
@@ -1153,9 +1153,7 @@ class PeerSummary:
                 and srcadr != "0.0.0.0" \
                 and not srcadr.startswith("127.127") \
                 and srcadr != "::":
-            if self.showhostnames & 2 and 'srchost' in locals() and srchost:
-                clock_name = srchost
-            elif self.showhostnames & 1:
+            if self.showhostnames:
                 try:
                     if self.debug:
                         self.logfp.write("DNS lookup begins...\n")
@@ -1236,7 +1234,7 @@ class MRUSummary:
         self.debug = debug
         self.logfp = logfp
         self.now = None
-        self.showhostnames = showhostnames  # if & 1, display names
+        self.showhostnames = showhostnames  # if True, display names
         self.wideremote = wideremote
 
     header = " lstint avgint rstr r m v  count    score   drop rport remote address"
@@ -1272,7 +1270,7 @@ class MRUSummary:
             rscode = '.'
         (ip, port) = portsplit(entry.addr)
         try:
-            if not self.showhostnames & 1:  # if not & 1 display numeric IPs
+            if not self.showhostnames:  # if False display numeric IPs
                 dns = ip
             else:
                 dns = canonicalize_dns(ip)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/10ee1b55f8c0c8866f409985e3013335d0ea1c49...9beb8ad48a1f61e5fe76561948066d8f6606ff08

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/10ee1b55f8c0c8866f409985e3013335d0ea1c49...9beb8ad48a1f61e5fe76561948066d8f6606ff08
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20260713/8b3c357f/attachment-0001.htm>


More information about the vc mailing list