]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Log failure to fetch time from HOPF_P hardware.
authorDave Hart <hart@ntp.org>
Thu, 14 Apr 2011 05:30:10 +0000 (05:30 +0000)
committerDave Hart <hart@ntp.org>
Thu, 14 Apr 2011 05:30:10 +0000 (05:30 +0000)
Check HOPF_S sscanf() conversion count before converted values.
Correct mvsnprintf() and mvfprintf() for vsnprintf() that handles %m.

bk: 4da68662IeXVWWM1aJhv-GKoRH6mrw

ChangeLog
libntp/msyslog.c
ntpd/refclock_hopfpci.c
ntpd/refclock_hopfser.c
sntp/crypto.c
sntp/main.c

index f2e1ba486f514dc3404d5f232b026c0fac82a999..8431a7e98a53a763ba8e6fb3c7d7632d63635451 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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@ntp.org>
 * Remove never-used, incomplete ports/winnt/ntpd/refclock_trimbledc.[ch]
 * On systems without C99-compliant (v)snprintf(), use C99-snprintf
index 18814b5c9fc5d2c3f7a87b3adf519d1eb14db023..fb6f80556499f2415eaa46f1a1595dc0c601e155 100644 (file)
@@ -49,56 +49,7 @@ void format_errmsg   (char *, size_t, const char *, int);
 # 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,
@@ -141,6 +92,56 @@ format_errmsg(
 #endif /* VSNPRINTF_PERCENT_M */
 
 
+/*
+ * 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
@@ -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
index 11fc9a0bf4157e3b660448d1c81459d39b156236..95abfe12de4c2d9f675285f67fa7684d42dbdc95 100644 (file)
@@ -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
index 699f0e86ff6488ee6151dd2585c87e0674a62557..6ae6d3cdbb28b1dda4440bce7cd061cfa3c9b488 100644 (file)
@@ -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)) {
index b427e1fab7728eab8da7ed6fac90242474f59f58..aa8d91dd222a53987645866f0f3c90b6f00b1bec 100644 (file)
@@ -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);
index f191476b2a1e08b01512b5b793fc98548f7c6019..e65c9bbe25bc49b9f9665c014250a825e8e3f4fd 100644 (file)
@@ -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;