Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/timed/timed PR bin/42464: Timothy McIntosh: Fix tim...



details:   https://anonhg.NetBSD.org/src/rev/b6b1065ee846
branches:  trunk
changeset: 355724:b6b1065ee846
user:      ginsbach <ginsbach%NetBSD.org@localhost>
date:      Fri Aug 11 16:47:42 2017 +0000

description:
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.

diffstat:

 usr.sbin/timed/timed/readmsg.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r 9a78f8fb23cd -r b6b1065ee846 usr.sbin/timed/timed/readmsg.c
--- a/usr.sbin/timed/timed/readmsg.c    Fri Aug 11 16:03:14 2017 +0000
+++ b/usr.sbin/timed/timed/readmsg.c    Fri Aug 11 16:47:42 2017 +0000
@@ -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 @@
                        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;
                }



Home | Main Index | Thread Index | Old Index