[Git][NTPsec/ntpsec][master] Fix ntpq -p bug introduced by "End type-punning around the refid field."

Eric S. Raymond gitlab at mg.gitlab.com
Tue Jan 29 15:57:55 UTC 2019


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
5367f15f by Eric S. Raymond at 2019-01-29T15:56:46Z
Fix ntpq -p bug introduced by "End type-punning around the refid field."

Also, factor refid dumping properly.

- - - - -


4 changed files:

- include/ntpd.h
- ntpd/ntp_control.c
- ntpd/ntp_io.c
- ntpd/ntp_util.c


Changes:

=====================================
include/ntpd.h
=====================================
@@ -420,4 +420,7 @@ extern struct refclock * const refclock_conf[];
 extern const uint8_t	num_refclock_conf;
 #endif
 
+/* ntp_util.c */
+extern char * refid_dump(refid_t, int);
+
 #endif	/* GUARD_NTPD_H */


=====================================
ntpd/ntp_control.c
=====================================
@@ -1382,8 +1382,10 @@ ctl_putadr(
 
 	*cp++ = '=';
 	if (NULL == addr) {
-		/* refid is an IPv4 address in binary format, just copy it */
-		cq = refid;
+		if (NULL == refid)
+			cq = "";
+		else
+			cq = refid_dump(refid, 1);
 	}
 	else
 		cq = socktoa(addr);
@@ -1406,8 +1408,8 @@ ctl_putrefid(
 	char	output[16];
 	char *	optr;
 	char *	oplim;
-	char *	iptr;
-	char *	iplim;
+	unsigned char *	iptr;
+	unsigned char *	iplim;
 	char *	past_eq = NULL;
 
 	optr = output;
@@ -2135,7 +2137,7 @@ ctl_putpeer(
 		break;
 
 	case CP_DSTADR:
-		ctl_putadr(peer_var[id].text, 0,
+		ctl_putadr(peer_var[id].text, NULL,
 			   (p->dstadr != NULL)
 				? &p->dstadr->sin
 				: NULL);


=====================================
ntpd/ntp_io.c
=====================================
@@ -394,9 +394,7 @@ interface_dump(const endpt *itf)
 	sockaddr_dump(&itf->mask);
 	printf("name = %s\n", itf->name);
 	printf("flags = 0x%08x\n", itf->flags);
-	printf("addr_refid = %02x%02x%02x%02x\n",
-	       itf->addr_refid[0], itf->addr_refid[1],
-	       itf->addr_refid[2], itf->addr_refid[3]);
+	printf("addr_refid = %s\n", refid_dump(itf->addr_refid));
 	printf("received = %ld\n", itf->received);
 	printf("sent = %ld\n", itf->sent);
 	printf("notsent = %ld\n", itf->notsent);


=====================================
ntpd/ntp_util.c
=====================================
@@ -787,3 +787,17 @@ ntpd_time_stepped(void)
 		mon_start((int)saved_mon_enabled);
 	}
 }
+
+char *
+refid_dump(refid_t refid, int mode)
+{
+    static char outbuf[16];
+    char const *fmt;
+    switch (mode) {
+    case 0: fmt = "%s";	break;
+    case 1: fmt = "%u.%u.%u.%u"; break;
+    default: fmt = "%02x%02x%02x%02x"; break;
+    }
+    snprintf(outbuf, sizeof(outbuf), fmt, refid[0],refid[1],refid[2],refid[3]);
+    return outbuf;
+}



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5367f15fa83420ac3f65651ed077e4c0a8011eaa

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5367f15fa83420ac3f65651ed077e4c0a8011eaa
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190129/5fd8f877/attachment-0001.html>


More information about the vc mailing list