From: Dave Hart Date: Tue, 24 Nov 2009 14:51:38 +0000 (+0000) Subject: [Bug 1387] free() conf_entry in ntp_intres removeentry(). X-Git-Tag: NTP_4_2_5P248_RC~4^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e1d8ac75e2b97ffcc5c26c0cdbf7a57b608d823;p=thirdparty%2Fntp.git [Bug 1387] free() conf_entry in ntp_intres removeentry(). [Bug 1392] intres retries duplicate assocations endlessly. bk: 4b0bf2falaNCS43VNSA6FdySaJfxsw --- diff --git a/ChangeLog b/ChangeLog index 4cb3832b8..2e96bac71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ * [Bug 1387] Storage leak in ntp_intres (minor). * [Bug 1389] buffer overflow in refclock_oncore.c * [Bug 1391] .texi usage text from installed, not built binaries. +* [Bug 1392] intres retries duplicate assocations endlessly. * Correct *-opts.h dependency so default 'get' action isn't used. (4.2.5p247-RC) 2009/11/20 Released by Harlan Stenn * [Bug 1142] nodebug builds shed no light on -d, -D option failure. diff --git a/ntpd/ntp_intres.c b/ntpd/ntp_intres.c index f6dcd341a..32ddff749 100644 --- a/ntpd/ntp_intres.c +++ b/ntpd/ntp_intres.c @@ -148,7 +148,8 @@ char *req_file; /* name of the file with configuration info */ static void checkparent (void); -static void removeentry (struct conf_entry *); +static struct conf_entry * + removeentry (struct conf_entry *); static void addentry (char *, int, int, int, int, u_int, int, keyid_t, char *); static int findhostaddr (struct conf_entry *); @@ -389,26 +390,30 @@ checkparent(void) /* * removeentry - we are done with an entry, remove it from the list */ -static void +static struct conf_entry * removeentry( struct conf_entry *entry ) { register struct conf_entry *ce; + struct conf_entry *next_ce; ce = confentries; - if (ce == entry) { + if (ce == entry) confentries = ce->ce_next; - return; - } - - while (ce != NULL) { - if (ce->ce_next == entry) { - ce->ce_next = entry->ce_next; - return; + else + while (ce != NULL) { + if (ce->ce_next == entry) { + ce->ce_next = entry->ce_next; + break; + } + ce = ce->ce_next; } - ce = ce->ce_next; - } + + next_ce = entry->ce_next; + free(entry); + + return next_ce; } @@ -841,7 +846,7 @@ request( return 0; } #endif /* SYS_WINNT */ - + /* * Wait for a response. A weakness of the mode 7 protocol used @@ -987,6 +992,13 @@ request( /* success */ return 1; + case INFO_ERR_NODATA: + /* + * newpeer() refused duplicate association, no + * point in retrying so call it success. + */ + return 1; + case INFO_ERR_IMPL: msyslog(LOG_ERR, "ntp_intres.request: implementation mismatch"); @@ -1002,11 +1014,6 @@ request( "ntp_intres.request: format error"); return 0; - case INFO_ERR_NODATA: - msyslog(LOG_ERR, - "ntp_intres.request: no data available"); - return 0; - case INFO_ERR_AUTH: msyslog(LOG_ERR, "ntp_intres.request: permission denied"); @@ -1182,7 +1189,6 @@ doconfigure( ) { register struct conf_entry *ce; - register struct conf_entry *ceremove; #ifdef DEBUG if (debug > 1) @@ -1208,19 +1214,18 @@ doconfigure( msyslog(LOG_ERR, "couldn't resolve `%s', giving up on it", ce->ce_name); - ceremove = ce; - ce = ceremove->ce_next; - removeentry(ceremove); + ce = removeentry(ce); continue; #endif - } + } else if (!SOCK_UNSPEC(&ce->peer_store)) + msyslog(LOG_INFO, + "DNS %s -> %s", ce->ce_name, + stoa(&ce->peer_store)); } if (!SOCK_UNSPEC(&ce->peer_store)) { if (request(&ce->ce_config)) { - ceremove = ce; - ce = ceremove->ce_next; - removeentry(ceremove); + ce = removeentry(ce); continue; } /* diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index 1a800bd2b..8530089f4 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -811,17 +811,12 @@ newpeer( peer->maxpoll = (u_char)max(maxpoll, NTP_MINPOLL); if (peer->minpoll > peer->maxpoll) peer->minpoll = peer->maxpoll; -#ifdef DEBUG - if (debug > 2) { - if (peer->dstadr) - printf("newpeer: using fd %d and our addr %s\n", - peer->dstadr->fd, - stoa(&peer->dstadr->sin)); - else - printf("newpeer: local interface currently not bound\n"); - } -#endif - + + if (peer->dstadr) + DPRINTF(3, ("newpeer: using fd %d and our addr %s\n", + peer->dstadr->fd, stoa(&peer->dstadr->sin))); + else + DPRINTF(3, ("newpeer: local interface currently not bound\n")); /* * Broadcast needs the socket enabled for broadcast