From: Harlan Stenn Date: Sun, 29 Jul 2007 19:44:57 +0000 (-0400) Subject: ntp_peer.c, ChangeLog: X-Git-Tag: NTP_4_2_5P64~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5feba7db0813441b946b23bcb43d293e6a75458;p=thirdparty%2Fntp.git ntp_peer.c, ChangeLog: Set peer->srcadr before (not after) calling set_peerdstadr() ntp_util.c, ChangeLog: Leap file related cleanup from Dave Mills ntp_io.c, ChangeLog: Dead code cleanup - Coverity View 19 bk: 46acee39w4pjmhiaGfftIzgpyeJ5Cg --- diff --git a/ChangeLog b/ChangeLog index 40b0d48cd..92800c8bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +* 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. diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 413b5e64e..5e82362af 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -2931,19 +2931,6 @@ read_network_packet(SOCKET fd, struct interface *itf, l_fp ts) 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) diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index 21473c36f..0a24aaf45 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -525,16 +525,17 @@ peer_config( } /* - * 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 @@ -542,19 +543,16 @@ set_peerdstadr(struct peer *peer, struct interface *interface) */ 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) : "", - (interface != NULL) ? - stoa(&interface->sin) : "")); + msyslog(LOG_INFO, + "set_peerdstadr(%s): change interface from %s to %s\n", + stoa(&peer->srcadr), (peer->dstadr != NULL) ? + stoa(&peer->dstadr->sin) : "", (interface != + NULL) ? stoa(&interface->sin) : ""); peer->dstadr = interface; if (peer->dstadr != NULL) { ISC_LIST_APPEND(peer->dstadr->peers, peer, @@ -756,11 +754,9 @@ newpeer( 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); diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index be38c0e8c..bac2267df 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -782,8 +782,6 @@ leap_file( 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); @@ -802,52 +800,38 @@ leap_file( /* * 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); }