Module Name:    src
Committed By:   ginsbach
Date:           Fri Aug 11 16:47:42 UTC 2017

Modified Files:
        src/usr.sbin/timed/timed: readmsg.c

Log Message:
PR bin/42464: Timothy McIntosh: Fix timed interoperability

Fix is a combination of FreeBSD fix and submitted patch.

[From the FreeBSD change]
The timed protocol is not implemented in a compatible way by all
vendors; the size of the tsp_name field is OS-dependent.  4.3BSD
used a 32-byte field, FreeBSD uses MAXHOSTNAMELEN and RedHat
apparently uses a 64-byte field.  As a result, sanity checking code
added a few months ago to detect short packets will fail when
interoperating with one of these other vendors.

Change the short packet detection code to expect a minimum packet
size corresponding to the 4.3BSD implementation, which should be
a safe minimum size.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/timed/timed/readmsg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/timed/timed/readmsg.c
diff -u src/usr.sbin/timed/timed/readmsg.c:1.22 src/usr.sbin/timed/timed/readmsg.c:1.23
--- src/usr.sbin/timed/timed/readmsg.c:1.22	Sat Feb 16 07:30:15 2008
+++ src/usr.sbin/timed/timed/readmsg.c	Fri Aug 11 16:47:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: readmsg.c,v 1.22 2008/02/16 07:30:15 matt Exp $	*/
+/*	$NetBSD: readmsg.c,v 1.23 2017/08/11 16:47:42 ginsbach Exp $	*/
 
 /*-
  * Copyright (c) 1985, 1993 The Regents of the University of California.
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)readmsg.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: readmsg.c,v 1.22 2008/02/16 07:30:15 matt Exp $");
+__RCSID("$NetBSD: readmsg.c,v 1.23 2017/08/11 16:47:42 ginsbach Exp $");
 #endif
 #endif /* not lint */
 
@@ -203,15 +203,22 @@ again:
 			continue;
 		}
 		length = sizeof(from);
+		memset(&msgin, 0, sizeof(msgin));
 		if ((n = recvfrom(sock, &msgin, sizeof(struct tsp), 0,
 			     (struct sockaddr*)(void *)&from, &length)) < 0) {
 			syslog(LOG_ERR, "recvfrom: %m");
 			exit(EXIT_FAILURE);
 		}
-		if (n < (ssize_t)sizeof(struct tsp)) {
+		/*
+		 * The 4.3BSD protocol spec had a 32-byte tsp_name field, and
+		 * this is still OS-dependent.  Demand that the packet is at
+		 * least long enough to hold a 4.3BSD packet.
+		 */
+		if (n < (ssize_t)(sizeof(struct tsp) - MAXHOSTNAMELEN + 32)) {
 			syslog(LOG_NOTICE,
 			    "short packet (%lu/%lu bytes) from %s",
-			      (u_long)n, (u_long)sizeof(struct tsp),
+			      (u_long)n,
+			      (u_long)(sizeof(struct tsp) - MAXHOSTNAMELEN + 32),
 			      inet_ntoa(from.sin_addr));
 			continue;
 		}

Reply via email to