+* ntp_io.c: Dead code cleanup - Coverity View 19.
+* Leap file related cleanup from Dave Mills.
+* ntp_peer.c: Set peer->srcadr before (not after) calling set_peerdstadr().
* Initialize offset in leap_file() - Coverity View 17.
* Use the correct stratum on KISS codes.
* Fuzz bits cleanup.
return (rb->recv_length);
}
- /*
- * Make sure only a valide broadcast packet was received
- * on the wildcard address
- */
- if (ignore_this == ISC_TRUE) {
- freerecvbuf(rb);
- DPRINTF(4, ("%s on (%lu) fd=%d from %s\n",
- "ignore", free_recvbuffs(), fd, stoa(&rb->recv_srcadr)));
- packets_ignored++;
- return (rb->recv_length);
- }
-
-
#ifdef DEBUG
if (debug > 2) {
if(rb->recv_srcadr.ss_family == AF_INET)
}
/*
- * setup peer dstadr field keeping it in sync with the interface structures
+ * setup peer dstadr field keeping it in sync with the interface
+ * structures
*/
void
set_peerdstadr(struct peer *peer, struct interface *interface)
{
if (peer->dstadr != interface) {
- if (interface != NULL &&
- (peer->cast_flags & MDF_BCLNT) &&
- (interface->flags & INT_MCASTIF) &&
+ if (interface != NULL && (peer->cast_flags &
+ MDF_BCLNT) && (interface->flags & INT_MCASTIF) &&
peer->burst) {
+
/*
* don't accept updates to a true multicast
* reception interface while a BCLNT peer is
*/
return;
}
-
if (peer->dstadr != NULL) {
peer->dstadr->peercnt--;
ISC_LIST_UNLINK_TYPE(peer->dstadr->peers, peer,
ilink, struct peer);
}
-
- DPRINTF(4, ("set_peerdstadr(%s): change interface from %s to %s\n",
- stoa(&peer->srcadr),
- (peer->dstadr != NULL) ?
- stoa(&peer->dstadr->sin) : "<null>",
- (interface != NULL) ?
- stoa(&interface->sin) : "<null>"));
+ msyslog(LOG_INFO,
+ "set_peerdstadr(%s): change interface from %s to %s\n",
+ stoa(&peer->srcadr), (peer->dstadr != NULL) ?
+ stoa(&peer->dstadr->sin) : "<null>", (interface !=
+ NULL) ? stoa(&interface->sin) : "<null>");
peer->dstadr = interface;
if (peer->dstadr != NULL) {
ISC_LIST_APPEND(peer->dstadr->peers, peer,
cast_flags, stoa(srcadr)));
ISC_LINK_INIT(peer, ilink); /* set up interface link chain */
-
+ peer->srcadr = *srcadr;
set_peerdstadr(peer, select_peerinterface(peer, srcadr, dstadr,
cast_flags));
-
- peer->srcadr = *srcadr;
peer->hmode = (u_char)hmode;
peer->version = (u_char)version;
peer->minpoll = (u_char)max(NTP_MINPOLL, minpoll);
u_long expire; /* NTP time when file expires */
int offset; /* TAI offset at leap (s) */
char filename[MAXFILENAME]; /* name of leapseconds file */
- char *dp;
- int i;
NTP_REQUIRE(cp != NULL);
/*
* Read and parse the leapseconds file. Empty lines and comments
- * are ignored. Other lines must begin with two integers
- * followed by junk or comments. The first integer is the NTP
- * seconds at the leap, the second is the TAI offset after the
- * leap. The second word must equal the initial insertion of ten
- * seconds on 1 January 1972 plus one second for each succeeding
- * insertion. The line beginning with #@ contains the file
- * expiration time in NTP seconds.
- */
- i = TAI_1972;
+ * are ignored. A line beginning with #@ contains the file
+ * expiration time in NTP seconds. Other lines begin with two
+ * integers followed by junk or comments. The first integer is
+ * the NTP seconds at the leap, the second is the TAI offset
+ * after the leap. Only the last correctly parsed line is
+ * significant. Parsing errors are cheerfully ignored.
+ */
offset = 0;
+ leapsec = 0;
expire = 0;
- while (i < MAX_TAI) {
- dp = fgets(buf, NTP_MAXSTRLEN - 1, str);
- if (dp == NULL)
- break;
-
+ while (fgets(buf, NTP_MAXSTRLEN - 1, str) != NULL) {
if (strlen(buf) < 1)
continue;
if (buf[0] == '#') {
+ if (strlen(buf) < 3)
+ continue;
+
if (buf[1] == '@') {
- if (sscanf(&buf[2], "%lu", &expire) !=
- 1)
- break;
+ sscanf(&buf[2], "%lu", &expire);
+ continue;
}
- continue;
}
-
- if (sscanf(buf, "%lu %d", &leapsec, &offset) != 2)
- continue;
-
- if (i != offset)
- break;
- i++;
+ sscanf(buf, "%lu %d", &leapsec, &offset);
}
fclose(str);
- if (offset == 0 || i != offset) {
- msyslog(LOG_INFO, "leap_file: %s error", cp);
- } else {
- leap_tai = offset;
- leap_ins = leapsec;
- leap_expire = expire;
- msyslog(LOG_INFO,
- "leap_file: %s TAI offset %d s insert %lu expire %lu",
- cp, leap_tai, leap_ins, leap_expire);
- }
+ leap_tai = offset;
+ leap_ins = leapsec;
+ leap_expire = expire;
+ msyslog(LOG_INFO,
+ "leap_file: %s TAI offset %d s insert %lu expire %lu",
+ cp, leap_tai, leap_ins, leap_expire);
}