Check HOPF_S sscanf() conversion count before converted values.
Correct mvsnprintf() and mvfprintf() for vsnprintf() that handles %m.
bk: 4da68662IeXVWWM1aJhv-GKoRH6mrw
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
# 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,
#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
)
{
#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
)
{
#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
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
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.
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
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)) {
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))
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);
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...
++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... */
}
/* 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;