]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Add missing "break;" to ntp_control.c ctl_putsys() for caliberrs, used
authorDave Hart <hart@ntp.org>
Wed, 9 Feb 2011 07:14:49 +0000 (07:14 +0000)
committerDave Hart <hart@ntp.org>
Wed, 9 Feb 2011 07:14:49 +0000 (07:14 +0000)
  by ntpq -c kerninfo introduced in 4.2.7p104.
Fix leak in ntp_control.c read_mru_list().

bk: 4d523ee9-RNRz2dQG8DNanCBLKnflA

ChangeLog
include/ntp_assert.h
include/ntp_lists.h
ntpd/ntp_control.c
ntpd/ntp_io.c
ntpd/ntp_monitor.c

index d2fc5d44420c7841f4c32f69ea686f70d64aac5c..ac2d35c2ffc07aebcd73ce60ab9ff33b57fbf27f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+* Add missing "break;" to ntp_control.c ctl_putsys() for caliberrs, used
+  by ntpq -c kerninfo introduced in 4.2.7p104.
+* Fix leak in ntp_control.c read_mru_list().
 (4.2.7p128) 2011/01/30 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1799] ntpq mrv crash.
 * [Bug 1801] ntpq mreadvar requires prior association caching.
index cbb863a60ed49c8bd6632a90447f785b0833f573..ab9b41981be686c9d41ea6da8a67ad0f7760c8a2 100644 (file)
@@ -36,7 +36,11 @@ extern void calysto_assert(unsigned char cnd); /* check whether this holds */
 #define ALWAYS_INVARIANT(x)    calysto_assume(x)
 #define ALWAYS_ENSURE(x)       calysto_assert(x)
 
-# elif defined(__COVERITY__)
+/* # elif defined(__COVERITY__) */
+/*
+ * DH: try letting coverity scan our actual assertion macros, now that
+ * isc_assertioncallback_t is marked __attribute__ __noreturn__.
+ */
 
 /*
  * Coverity has special knowledge that assert(x) terminates the process
@@ -46,10 +50,12 @@ extern void calysto_assert(unsigned char cnd); /* check whether this holds */
  * that seems to be a reasonable trade-off.
  */
 
+/*
 #define ALWAYS_REQUIRE(x)      assert(x)
 #define ALWAYS_INSIST(x)       assert(x)
 #define ALWAYS_INVARIANT(x)    assert(x)
 #define ALWAYS_ENSURE(x)       assert(x)
+*/
 
 # else /* neither Coverity nor Calysto */
 
index 4657820518ecb19ba6c0ddc92596b8bd6b73ce86..4364e64529d18e4028452ee8b91c70a7e4d62def 100644 (file)
 #ifndef NTP_LISTS_H
 #define NTP_LISTS_H
 
+#include "ntp_types.h"         /* TRUE and FALSE */
 #include "ntp_assert.h"
 
-/*
- * For now enable extra debugging code on all builds.  Before long, it
- * will probably make sense to only include the debugging #ifdef DEBUG
- */
-#define NTP_DEBUG_LISTS_H
-
 /*
  * If list debugging is not enabled, save a little time by not clearing
  * an entry's link pointer when it is unlinked, as the stale pointer
 #define MAYBE_Z_LISTS(p)       (p) = NULL
 #endif
 
-#ifndef TRUE
-# define TRUE  1
-# define NTP_LISTS_UNDEF_TRUE
-#endif
-
 #define LINK_SLIST(listhead, pentry, nextlink)                 \
 do {                                                           \
        (pentry)->nextlink = (listhead);                        \
@@ -158,8 +148,8 @@ do {                                                                \
        entrytype **ppentry;                                    \
                                                                \
        ppentry = &(listhead);                                  \
-       while (*ppentry != NULL) {                              \
-               if (beforecur) {                                \
+       while (TRUE) {                                          \
+               if (NULL == *ppentry || (beforecur)) {          \
                        (pentry)->nextlink = *ppentry;          \
                        *ppentry = (pentry);                    \
                        break;                                  \
@@ -171,7 +161,7 @@ do {                                                                \
                        break;                                  \
                }                                               \
        }                                                       \
-} while (0)
+} while (FALSE)
 
 #define UNLINK_HEAD_SLIST(punlinked, listhead, nextlink)       \
 do {                                                           \
@@ -390,9 +380,4 @@ do {                                                                \
        }                                                       \
 }
 
-
-#ifdef NTP_LISTS_UNDEF_TRUE
-# undef TRUE
-#endif
-
 #endif /* NTP_LISTS_H */
index fb7881806970bd194fbfafaa1c34146c57b3f135..75450a4a257949b272f0d874f49630e4b39e133a 100644 (file)
@@ -2111,6 +2111,7 @@ ctl_putsys(
                        ctl_putint,
                        (sys_var[varid].text, ntx.errcnt)
                );
+               break;
 
        case CS_K_PPS_JITEXC:
                CTL_IF_KERNPPS(
@@ -3543,9 +3544,11 @@ static void read_mru_list(
        while (NULL != (v = ctl_getitem(in_parms, &val)) &&
               !(EOV & v->flags)) {
 
-               if (!strcmp(nonce_text, v->text))
+               if (!strcmp(nonce_text, v->text)) {
+                       if (NULL != pnonce)
+                               free(pnonce);
                        pnonce = estrdup(val);
-               else if (!strcmp(limit_text, v->text))
+               else if (!strcmp(limit_text, v->text))
                        sscanf(val, "%u", &limit);
                else if (!strcmp(mincount_text, v->text)) {
                        if (1 != sscanf(val, "%d", &mincount) ||
index 20a803cbf3d43e78330aad7f41f494f97023f09b..8f0b494a48ff862e1cc1b6b2766d9cc146cdddae 100644 (file)
@@ -1108,10 +1108,14 @@ add_interface(
                    ? "4"
                    : "6"));
 
+       if (INVALID_SOCKET == ep->fd)
+               return;
+
        /*
         * select the local address from which to send to multicast.
         */
        switch (AF(&ep->sin)) {
+
        case AF_INET :
                rc = setsockopt(ep->fd, IPPROTO_IP,
                                IP_MULTICAST_IF,
@@ -1122,6 +1126,7 @@ add_interface(
                                "setsockopt IP_MULTICAST_IF %s fails: %m",
                                stoa(&ep->sin));
                break;
+
 # ifdef INCLUDE_IPV6_MULTICAST_SUPPORT
        case AF_INET6 :
                rc = setsockopt(ep->fd, IPPROTO_IPV6,
index cfead2345b60b937cb6ca88b5f850549245a1237..48dda53d6b713a8b6edf1901cae092eb6c313dd2 100644 (file)
@@ -161,6 +161,8 @@ mon_reclaim_entry(
        mon_entry *m
        )
 {
+       DEBUG_INSIST(NULL != m);
+
        UNLINK_DLIST(m, mru);
        remove_from_hash(m);
        ZERO(*m);
@@ -451,9 +453,9 @@ ntp_monitor(
                        UNLINK_HEAD_SLIST(mon, mon_free, hash_next);
                /* Preempt from the MRU list if old enough. */
                } else if (ntp_random() / (2. * FRAC) >
-                          (double)oldest_age / mon_age)
+                          (double)oldest_age / mon_age) {
                        return ~(RES_LIMITED | RES_KOD) & flags;
-               else {
+               else {
                        mon_reclaim_entry(oldest);
                        mon = oldest;
                }