[ntp:bk-ntp-dev-send] BitKeeper diffs

Harlan Stenn stenn at deacon.udel.edu
Thu Apr 14 05:48:08 UTC 2011


#### ChangeSet ####
2011-04-14 05:30:10+00:00, davehart at shiny.ad.hartbrothers.com
  Log failure to fetch time from HOPF_P hardware.
  Check HOPF_S sscanf() conversion count before converted values.
  Correct mvsnprintf() and mvfprintf() for vsnprintf() that handles %m.

==== ChangeLog ====
2011-04-14 05:30:09+00:00, davehart at shiny.ad.hartbrothers.com +2 -0
  Log failure to fetch time from HOPF_P hardware.
  Check HOPF_S sscanf() conversion count before converted values.

--- 1.846/ChangeLog	2011-04-13 22:00:00 -04:00
+++ 1.847/ChangeLog	2011-04-14 01:30:09 -04:00
@@ -3,6 +3,8 @@
   flock-build to avoid regressions in (v)snprintf() replacement.
 * More msnprintf() unit tests.
 * Coverity Scan error checking fixes.
+* Log failure to fetch time from HOPF_P hardware.
+* Check HOPF_S sscanf() conversion count before converted values.
 (4.2.7p150) 2011/04/13 Released by Harlan Stenn <stenn at ntp.org>
 * Remove never-used, incomplete ports/winnt/ntpd/refclock_trimbledc.[ch]
 * On systems without C99-compliant (v)snprintf(), use C99-snprintf

==== libntp/msyslog.c ====
2011-04-14 05:30:09+00:00, davehart at shiny.ad.hartbrothers.com +59 -54
  Correct mvsnprintf() and mvfprintf() for vsnprintf() that handles %m.

--- 1.41/libntp/msyslog.c	2011-04-13 22:00:00 -04:00
+++ 1.42/libntp/msyslog.c	2011-04-14 01:30:09 -04:00
@@ -49,56 +49,7 @@ void	format_errmsg	(char *, size_t, cons
 # endif
 
 
-/*
- * errno_to_str() - a thread-safe strerror() replacement.
- *		    Hides the varied signatures of strerror_r().
- *		    For Windows, we have:
- *			#define errno_to_str isc_strerror
- */
-# ifndef errno_to_str
-void
-errno_to_str(
-	int	err,
-	char *	buf,
-	size_t	bufsiz
-	)
-{
-#  if defined(STRERROR_R_CHAR_P) || !HAVE_DECL_STRERROR_R
-	char *	pstatic;
-
-	buf[0] = '\0';
-#   ifdef STRERROR_R_CHAR_P
-	/*
-	 * For older GNU strerror_r, the return value either points to
-	 * buf, or to static storage.  We want the result always in buf
-	 */
-	pstatic = strerror_r(err, buf, bufsiz);
-#   else
-	pstatic = strerror(err);
-#   endif
-	if (NULL == pstatic && '\0' == buf[0])
-		snprintf(buf, bufsiz, "%s(%d): errno %d",
-#   ifdef STRERROR_R_CHAR_P
-			 "strerror_r",
-#   else
-			 "strerror",
-#   endif
-			 err, errno);
-	/* protect against believing an int return is a pointer */
-	else if (pstatic != buf && pstatic > (char *)bufsiz)
-		strlcpy(buf, pstatic, bufsiz);
-#  else
-	int	rc;
-
-	rc = strerror_r(err, buf, bufsiz);
-	if (rc < 0)
-		snprintf(buf, bufsiz, "strerror_r(%d): errno %d",
-			 err, errno);
-#  endif
-}
-# endif	/* errno_to_str */
-
-
+/* format_errmsg() is under #ifndef VSNPRINTF_PERCENT_M above */
 void
 format_errmsg(
 	char *		nfmt,
@@ -142,6 +93,56 @@ format_errmsg(
 
 
 /*
+ * errno_to_str() - a thread-safe strerror() replacement.
+ *		    Hides the varied signatures of strerror_r().
+ *		    For Windows, we have:
+ *			#define errno_to_str isc_strerror
+ */
+#ifndef errno_to_str
+void
+errno_to_str(
+	int	err,
+	char *	buf,
+	size_t	bufsiz
+	)
+{
+# if defined(STRERROR_R_CHAR_P) || !HAVE_DECL_STRERROR_R
+	char *	pstatic;
+
+	buf[0] = '\0';
+#  ifdef STRERROR_R_CHAR_P
+	/*
+	 * For older GNU strerror_r, the return value either points to
+	 * buf, or to static storage.  We want the result always in buf
+	 */
+	pstatic = strerror_r(err, buf, bufsiz);
+#  else
+	pstatic = strerror(err);
+#  endif
+	if (NULL == pstatic && '\0' == buf[0])
+		snprintf(buf, bufsiz, "%s(%d): errno %d",
+#  ifdef STRERROR_R_CHAR_P
+			 "strerror_r",
+#  else
+			 "strerror",
+#  endif
+			 err, errno);
+	/* protect against believing an int return is a pointer */
+	else if (pstatic != buf && pstatic > (char *)bufsiz)
+		strlcpy(buf, pstatic, bufsiz);
+# else
+	int	rc;
+
+	rc = strerror_r(err, buf, bufsiz);
+	if (rc < 0)
+		snprintf(buf, bufsiz, "strerror_r(%d): errno %d",
+			 err, errno);
+# endif
+}
+#endif	/* errno_to_str */
+
+
+/*
  * addto_syslog()
  * This routine adds the contents of a buffer to the syslog or an
  * application-specific logfile.
@@ -225,9 +226,11 @@ mvsnprintf(
 	)
 {
 #ifndef VSNPRINTF_PERCENT_M
-	char	nfmt[256];
+	char		nfmt[256];
+#else
+	const char *	nfmt = fmt;
 #endif
-	int	errval;
+	int		errval;
 
 	/*
 	 * Save the error value as soon as possible
@@ -255,9 +258,11 @@ mvfprintf(
 	)
 {
 #ifndef VSNPRINTF_PERCENT_M
-	char	nfmt[256];
+	char		nfmt[256];
+#else
+	const char *	nfmt = fmt;
 #endif
-	int	errval;
+	int		errval;
 
 	/*
 	 * Save the error value as soon as possible

==== ntpd/refclock_hopfpci.c ====
2011-04-14 05:30:09+00:00, davehart at shiny.ad.hartbrothers.com +3 -1
  Log failure to fetch time from HOPF_P hardware.

--- 1.12/ntpd/refclock_hopfpci.c	2011-02-20 15:22:39 -05:00
+++ 1.13/ntpd/refclock_hopfpci.c	2011-04-14 01:30:09 -04:00
@@ -194,7 +194,9 @@ hopfpci_poll(
 	pp = peer->procptr;
 
 #ifndef SYS_WINNT
-	ioctl(fd,HOPF_CLOCK_GET_UTC,&m_time);
+	if (ioctl(fd, HOPF_CLOCK_GET_UTC, &m_time) < 0)
+		msyslog(LOG_ERR, "HOPF_P(%d): HOPF_CLOCK_GET_UTC: %m\n",
+			unit);
 #else
 	GetHopfSystemTime(&m_time);
 #endif

==== ntpd/refclock_hopfser.c ====
2011-04-14 05:30:09+00:00, davehart at shiny.ad.hartbrothers.com +11 -10
  Check HOPF_S sscanf() conversion count before converted values.

--- 1.15/ntpd/refclock_hopfser.c	2011-02-20 15:22:39 -05:00
+++ 1.16/ntpd/refclock_hopfser.c	2011-04-14 01:30:09 -04:00
@@ -215,10 +215,11 @@ hopfserial_receive (
 	struct refclockproc *pp;
 	struct peer *peer;
 
-	int		synch;	/* synchhronization indicator */
-	int		DoW;	/* Dow */
+	int	synch;	/* synchhronization indicator */
+	int	DoW;	/* Day of Week */
 
 	int	day, month;	/* ddd conversion */
+	int	converted;
 
 	/*
 	 * Initialize pointers and read the timecode and timestamp.
@@ -230,15 +231,15 @@ hopfserial_receive (
 	if (up->rpt_next == 0 )
 		return;
 
-
 	up->rpt_next = 0; /* wait until next poll interval occur */
 
-	pp->lencode = (u_short)refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &pp->lastrec);
-
-	if (pp->lencode  == 0)
+	pp->lencode = (u_short)refclock_gtlin(rbufp, pp->a_lastcode,
+					      sizeof(pp->a_lastcode),
+					      &pp->lastrec);
+	if (pp->lencode == 0)
 		return;
 
-	sscanf(pp->a_lastcode,
+	converted = sscanf(pp->a_lastcode,
 #if 1
 	       "%1x%1x%2d%2d%2d%2d%2d%2d",   /* ...cr,lf */
 #else
@@ -258,9 +259,9 @@ hopfserial_receive (
 	  Validate received values at least enough to prevent internal
 	  array-bounds problems, etc.
 	*/
-	if((pp->hour < 0) || (pp->hour > 23) ||
-	   (pp->minute < 0) || (pp->minute > 59) ||
-	   (pp->second < 0) || (pp->second > 60) /*Allow for leap seconds.*/ ||
+	if ((8 != converted) || (pp->hour < 0) || (pp->hour > 23) ||
+	   (pp->minute < 0) || (pp->minute > 59) || (pp->second < 0) ||
+	   (pp->second > 60) /*Allow for leap seconds.*/ ||
 	   (day < 1) || (day > 31) ||
 	   (month < 1) || (month > 12) ||
 	   (pp->year < 0) || (pp->year > 99)) {

==== sntp/crypto.c ====
2011-04-14 05:30:09+00:00, davehart at shiny.ad.hartbrothers.com +2 -1
  Minor leak fix.

--- 1.16/sntp/crypto.c	2011-01-09 01:52:02 -05:00
+++ 1.17/sntp/crypto.c	2011-04-14 01:30:09 -04:00
@@ -112,7 +112,7 @@ auth_init(
 	key_cnt = 0;
 	while (!feof(keyf)) {
 		char * octothorpe;
-		struct key *act = emalloc(sizeof(struct key));
+		struct key *act;
 		int goodline = 0;
 
 		if (NULL == fgets(kbuf, sizeof(kbuf), keyf))
@@ -122,6 +122,7 @@ auth_init(
 		octothorpe = strchr(kbuf, '#');
 		if (octothorpe)
 			*octothorpe = '\0';
+		act = emalloc(sizeof(*act));
 		scan_cnt = sscanf(kbuf, "%d %9s %128s", &act->key_id, act->type, keystring);
 		if (scan_cnt == 3) {
 			int len = strlen(keystring);

==== sntp/main.c ====
2011-04-14 05:30:09+00:00, davehart at shiny.ad.hartbrothers.com +7 -7
  nonfunctional, makes static analysis happy.

--- 1.70/sntp/main.c	2011-03-05 17:35:34 -05:00
+++ 1.71/sntp/main.c	2011-04-14 01:30:09 -04:00
@@ -498,11 +498,6 @@ sntp_name_resolved(
 				break;
 			}
 
-			spkt = emalloc_zero(sizeof(*spkt));
-			spkt->dctx = dctx;
-			octets = min(ai->ai_addrlen, sizeof(spkt->addr));
-			memcpy(&spkt->addr, ai->ai_addr, octets);
-
 			/*
 			** We're waiting for a response for either unicast
 			** or broadcast, so...
@@ -510,8 +505,13 @@ sntp_name_resolved(
 			++n_pending_ntp;
 
 			/* If this is for a unicast IP, queue a request */
-			if (dctx->flags & CTX_UCST)
+			if (dctx->flags & CTX_UCST) {
+				spkt = emalloc_zero(sizeof(*spkt));
+				spkt->dctx = dctx;
+				octets = min(ai->ai_addrlen, sizeof(spkt->addr));
+				memcpy(&spkt->addr, ai->ai_addr, octets);
 				queue_xmt(sock, dctx, spkt, xmt_delay);
+			}
 		}
 	}
 	/* n_pending_dns really should be >0 here... */
@@ -819,7 +819,7 @@ sock_cb(
 	}
 
 	/* Read in the packet */
-	rpktl = recvdata(fd, &sender, &r_pkt, sizeof(rbuf));
+	rpktl = recvdata(fd, &sender, &rbuf, sizeof(rbuf));
 	if (rpktl < 0) {
 		msyslog(LOG_DEBUG, "recvfrom error %m");
 		return;


More information about the bk-ntp-dev-send mailing list