]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Make sure the value returned by refid_str() prints cleanly
authorHarlan Stenn <stenn@ntp.org>
Sun, 7 May 2023 08:46:52 +0000 (03:46 -0500)
committerHarlan Stenn <stenn@ntp.org>
Sun, 7 May 2023 08:46:52 +0000 (03:46 -0500)
bk: 6457657cbmOY_RIfIqHA4VWtmCb0iw

ChangeLog
libntp/numtoa.c

index 667c836ec57232aefed7401472ed56b0e7ce6cbe..d58088e178c75e93f88c6ade4045dc945932dfaa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -89,6 +89,7 @@
 * Only define tv_fmt_libbuf() if we will use it. <stenn@ntp.org>
 * Use recv_buffer instead of the longer recv_space.X_recv_buffer. hart/stenn
 * Disable "embedded NUL in string" warnings in libopts, when we can. <stenn@>
+* Make sure the value returned by refid_str() prints cleanly. <stenn@ntp.org>
 * If DEBUG is enabled, the startup banner now says that debug assertions
   are in force and that ntpd will abort if any are violated. <stenn@ntp.org>
 * syslog valid incoming KoDs.  <stenn@ntp.org>
index 5efbe942e3b4e4f2f4a42ac24c594eab24426b6a..51645de01c30a574304531abfdb84da2fa04df93 100644 (file)
@@ -9,6 +9,7 @@
 #endif
 
 #include <stdio.h>
+#include <ctype.h>
 
 #include "ntp_fp.h"
 #include "lib_strbuf.h"
@@ -42,18 +43,33 @@ refid_str(
 {
        char *  text;
        size_t  tlen;
+       char *  cp;
 
        if (stratum > 1)
                return numtoa(refid);
 
        LIB_GETBUF(text);
        text[0] = '.';
+       /* What if any non-NUL char is not printable? */
        memcpy(&text[1], &refid, sizeof(refid));
        text[1 + sizeof(refid)] = '\0';
        tlen = strlen(text);
        text[tlen] = '.';
        text[tlen + 1] = '\0';
 
+       /*
+        * Now make sure the contents are 'graphic'.
+        *
+        * This refid is expected to be up to 4 ascii graphics.
+        * If any character is not a graphic, replace it with a space.
+        * This will at least alert the viewer of a problem.
+        */
+       for (cp = text + 1; *cp; ++cp) {
+               if (!isgraph((int)*cp)) {
+                       *cp = ' ';
+               }
+       }
+
        return text;
 }