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

netdate bug



Hello,

	I use the netdate program of the netstd package to set my clock
every so often, and recently it started failing. The reason apparently was
that the program ignored the RFC868 standard which specifies a 32 bit
reply from the remote host. It checked if the number of octets received
was less than sizeof(tv_sec), and if so, returned an error.

	tv_sec is defined in time.h as long int, which on the Alpha is 64
bits wide. I'm not sure if that violates POSIX, but that's out of scope.

	Furthermore, the code took additional octets as tv_usec, which
violates the standard. I don't know if some hosts do send time back like
that (they shouldn't), but that would have probably set the clock to a
wild value.

	Anyway, following this is a patch to the debian version of
netdate, which bails if it doesn't read exactly 4 octets. I also tried to
make it ANSI compliant, but sigjmp_buf is undefined at compile time.

Greetings,
Michael.
--- netdate.c.orig	Wed Aug 11 02:41:40 1999
+++ netdate.c	Wed Aug 11 01:55:14 1999
@@ -84,7 +84,7 @@
 
 void	usage (void);
 int	setproto (char *, struct timehost *);
-void	main (int, char **);
+int	main (int, char **);
 int	getdiff (struct timehost *);
 int	getdate (struct timehost *);
 void	printit (struct timehost *);
@@ -118,7 +118,8 @@
 int verbose = 0;
 int debug = 0;
 
-void
+/* main returns int according to ansi standard */
+int
 main (int argc, char **argv)
 {
 	extern char *rindex();
@@ -391,6 +392,7 @@
 		abs(diff->tv_sec), abs(diff->tv_usec) / 1000);
 }
 
+/* where does sigjmp_buf get defined? did not get def'd from setjmp.h */
 static	sigjmp_buf jb;
 void
 timeout()
@@ -465,14 +467,18 @@
 	(void)gettimeofday (&thishost -> acked, (struct timezone *)0);
 	(void)alarm(0);
 	now = thishost -> acked;
-	if (nread < sizeof(thishost -> then.tv_sec)) {
+	if (nread != 4) {
 		perror ("netdate: read");
 		goto bad;
 	}
 	/* RFC 868 only allows seconds, but what the hell */
+/* it's just a standard, you know. -ms */
+/*
 	if (nread == sizeof(thishost -> then))
 		thishost -> then.tv_usec = ntohl(thishost -> then.tv_usec);
 	else
+*/
+/* above text removed for standards compliance */
 		thishost -> then.tv_usec = 0L;
 	thishost -> then.tv_sec = ntohl (thishost -> then.tv_sec) - NETBASE;
 	return (1);	/* don't close before returning to avoid delays */



Reply to: