bk: 6457657cbmOY_RIfIqHA4VWtmCb0iw
* 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>
#endif
#include <stdio.h>
+#include <ctype.h>
#include "ntp_fp.h"
#include "lib_strbuf.h"
{
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;
}