]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4719. [bug] Address PVS static analyzer warnings. [RT #45946]
authorMark Andrews <marka@isc.org>
Tue, 12 Sep 2017 23:50:51 +0000 (09:50 +1000)
committerMark Andrews <marka@isc.org>
Tue, 12 Sep 2017 23:50:51 +0000 (09:50 +1000)
CHANGES
bin/dig/nslookup.c
bin/dnssec/dnssectool.c
lib/dns/adb.c
lib/dns/rbt.c
lib/dns/tsig.c
lib/isc/unix/interfaceiter.c
lib/ns/xfrout.c

diff --git a/CHANGES b/CHANGES
index 5fd606305ca206d1ec6324fc67cb67f8ac34453f..6a891e683fbca9ef840316b6667e97cd2afe5d8e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+4719.  [bug]           Address PVS static analyzer warnings. [RT #45946]
+
 4718.  [func]          Avoid seaching for a owner name compression pointer
                        more than once when writing out a RRset. [RT #45802]
 
index b124084065b577599bbc51e876324673450e2ead..613269d67bd91d5c9c2b049e77e1e3b8322012f1 100644 (file)
@@ -637,7 +637,12 @@ version(void) {
 
 static void
 setoption(char *opt) {
-       if (strncasecmp(opt, "all", 3) == 0) {
+       size_t l = strlen(opt);
+
+#define CHECKOPT(A, N) \
+       ((l >= N) && (l < sizeof(A)) && (strncasecmp(opt, A, l) == 0))
+
+       if (CHECKOPT("all", 3) == 0) {
                show_settings(ISC_TRUE, ISC_FALSE);
        } else if (strncasecmp(opt, "class=", 6) == 0) {
                if (testclass(&opt[6]))
@@ -691,43 +696,43 @@ setoption(char *opt) {
                set_timeout(&opt[8]);
        } else if (strncasecmp(opt, "t=", 2) == 0) {
                set_timeout(&opt[2]);
-       } else if (strncasecmp(opt, "rec", 3) == 0) {
+       } else if (CHECKOPT("recurse", 3)) {
                recurse = ISC_TRUE;
-       } else if (strncasecmp(opt, "norec", 5) == 0) {
+       } else if (CHECKOPT("norecurse", 5)) {
                recurse = ISC_FALSE;
        } else if (strncasecmp(opt, "retry=", 6) == 0) {
                set_tries(&opt[6]);
        } else if (strncasecmp(opt, "ret=", 4) == 0) {
                set_tries(&opt[4]);
-       } else if (strncasecmp(opt, "def", 3) == 0) {
+       } else if (CHECKOPT("defname", 3)) {
                usesearch = ISC_TRUE;
-       } else if (strncasecmp(opt, "nodef", 5) == 0) {
+       } else if (CHECKOPT("nodefname", 5)) {
                usesearch = ISC_FALSE;
-       } else if (strncasecmp(opt, "vc", 3) == 0) {
+       } else if (CHECKOPT("vc", 2) == 0) {
                tcpmode = ISC_TRUE;
                tcpmode_set = ISC_TRUE;
-       } else if (strncasecmp(opt, "novc", 5) == 0) {
+       } else if (CHECKOPT("novc", 4) == 0) {
                tcpmode = ISC_FALSE;
                tcpmode_set = ISC_TRUE;
-       } else if (strncasecmp(opt, "deb", 3) == 0) {
+       } else if (CHECKOPT("debug", 3) == 0) {
                short_form = ISC_FALSE;
                showsearch = ISC_TRUE;
-       } else if (strncasecmp(opt, "nodeb", 5) == 0) {
+       } else if (CHECKOPT("nodebug", 5) == 0) {
                short_form = ISC_TRUE;
                showsearch = ISC_FALSE;
-       } else if (strncasecmp(opt, "d2", 2) == 0) {
+       } else if (CHECKOPT("d2", 2) == 0) {
                debugging = ISC_TRUE;
-       } else if (strncasecmp(opt, "nod2", 4) == 0) {
+       } else if (CHECKOPT("nod2", 4) == 0) {
                debugging = ISC_FALSE;
-       } else if (strncasecmp(opt, "search", 3) == 0) {
+       } else if (CHECKOPT("search", 3) == 0) {
                usesearch = ISC_TRUE;
-       } else if (strncasecmp(opt, "nosearch", 5) == 0) {
+       } else if (CHECKOPT("nosearch", 5) == 0) {
                usesearch = ISC_FALSE;
-       } else if (strncasecmp(opt, "sil", 3) == 0) {
+       } else if (CHECKOPT("sil", 3) == 0) {
                /* deprecation_msg = ISC_FALSE; */
-       } else if (strncasecmp(opt, "fail", 3) == 0) {
+       } else if (CHECKOPT("fail", 3) == 0) {
                nofail=ISC_FALSE;
-       } else if (strncasecmp(opt, "nofail", 3) == 0) {
+       } else if (CHECKOPT("nofail", 5) == 0) {
                nofail=ISC_TRUE;
        } else if (strncasecmp(opt, "ndots=", 6) == 0) {
                set_ndots(&opt[6]);
index 4879c69942b48a4f505acbc20241adeae0f0eb83..dc05b745637426afdeda9cb735b89dbe3391e232 100644 (file)
@@ -1835,7 +1835,7 @@ verifyzone(dns_db_t *db, dns_dbversion_t *ver,
                for (i = 0; i < 256; i++) {
                        if ((ksk_algorithms[i] != 0) ||
                            (standby_ksk[i] != 0) ||
-                           (revoked_zsk[i] != 0) ||
+                           (revoked_ksk[i] != 0) ||
                            (zsk_algorithms[i] != 0) ||
                            (standby_zsk[i] != 0) ||
                            (revoked_zsk[i] != 0)) {
index 4a38ddf2456ee70da99e16ab83cc506882ffffeb..9af022e7ff42eb27b1507b46a6fcbb27f4a5dc44 100644 (file)
@@ -2172,7 +2172,7 @@ log_quota(dns_adbentry_t *entry, const char *fmt, ...) {
        isc_netaddr_format(&netaddr, addrbuf, sizeof(addrbuf));
 
        isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_ADB,
-                     ISC_LOG_INFO, "adb: quota %s (%d/%d): %s",
+                     ISC_LOG_INFO, "adb: quota %s (%u/%u): %s",
                      addrbuf, entry->active, entry->quota, msgbuf);
 }
 
@@ -2847,7 +2847,7 @@ void
 dns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp) {
        isc_task_t *tclone;
        isc_event_t *event;
-       isc_boolean_t zeroirefcnt = ISC_FALSE;
+       isc_boolean_t zeroirefcnt;
 
        /*
         * Send '*eventp' to 'task' when 'adb' has shutdown.
@@ -2860,8 +2860,8 @@ dns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp) {
        *eventp = NULL;
 
        LOCK(&adb->lock);
-
        LOCK(&adb->reflock);
+
        zeroirefcnt = ISC_TF(adb->irefcnt == 0);
 
        if (adb->shutting_down && zeroirefcnt &&
@@ -3498,10 +3498,10 @@ dump_adb(dns_adb_t *adb, FILE *f, isc_boolean_t debug, isc_stdtime_t now) {
                        print_namehook_list(f, "v6", adb,
                                            &name->v6, debug, now);
 
-                       if (debug)
+                       if (debug) {
                                print_fetch_list(f, name);
-                       if (debug)
                                print_find_list(f, name);
+                       }
                }
        }
 
@@ -3557,7 +3557,7 @@ dump_entry(FILE *f, dns_adb_t *adb, dns_adbentry_t *entry,
                fprintf(f, " [ttl %d]", entry->expires - now);
 
        if (adb != NULL && adb->quota != 0 && adb->atr_freq != 0) {
-               fprintf(f, " [atr %0.2f] [quota %d]",
+               fprintf(f, " [atr %0.2f] [quota %u]",
                        entry->atr, entry->quota);
        }
 
@@ -4232,6 +4232,8 @@ static int quota_adj[] = {
        312, 307, 303, 298, 294, 290, 286, 282, 278
 };
 
+#define QUOTA_ADJ_SIZE (sizeof(quota_adj)/sizeof(quota_adj[0]))
+
 /*
  * Caller must hold adbentry lock
  */
@@ -4270,12 +4272,13 @@ maybe_adjust_quota(dns_adb_t *adb, dns_adbaddrinfo_t *addr,
        if (addr->entry->atr < adb->atr_low && addr->entry->mode > 0) {
                addr->entry->quota = adb->quota *
                        quota_adj[--addr->entry->mode] / 10000;
-               log_quota(addr->entry, "atr %0.2f, quota increased to %d",
+               log_quota(addr->entry, "atr %0.2f, quota increased to %u",
                          addr->entry->atr, addr->entry->quota);
-       } else if (addr->entry->atr > adb->atr_high && addr->entry->mode < 99) {
+       } else if (addr->entry->atr > adb->atr_high &&
+                  addr->entry->mode < (QUOTA_ADJ_SIZE - 1)) {
                addr->entry->quota = adb->quota *
                        quota_adj[++addr->entry->mode] / 10000;
-               log_quota(addr->entry, "atr %0.2f, quota decreased to %d",
+               log_quota(addr->entry, "atr %0.2f, quota decreased to %u",
                          addr->entry->atr, addr->entry->quota);
        }
 
index 99da4066b7f827dcd3ceabfa9c765def6ddd37db..83163db3a4936f909b320294d186bed774ca536a 100644 (file)
@@ -868,6 +868,7 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize,
        file_header_t *header;
        dns_rbt_t *rbt = NULL;
        isc_uint64_t crc;
+       unsigned int host_big_endian;
 
        REQUIRE(originp == NULL || *originp == NULL);
        REQUIRE(rbtp != NULL && *rbtp == NULL);
@@ -897,7 +898,9 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize,
                result = ISC_R_INVALIDFILE;
                goto cleanup;
        }
-       if (header->bigendian != (1 == htonl(1)) ? 1 : 0) {
+
+       host_big_endian = (1 == htonl(1));
+       if (header->bigendian != host_big_endian) {
                result = ISC_R_INVALIDFILE;
                goto cleanup;
        }
index b7a3fb633b88e2818ca56e49fbbbb6c51f7080a0..ef2eb7fbb14837790b02a4913fea9b92caca0396 100644 (file)
@@ -1570,13 +1570,13 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) {
                addcount_n = ntohs(addcount);
                addcount = htons((isc_uint16_t)(addcount_n - 1));
                memmove(&header[DNS_MESSAGE_HEADERLEN - 2], &addcount, 2);
-       }
 
-       /*
-        * Put in the original id.
-        */
-       /* XXX Can TCP transfers be forwarded?  How would that work? */
-       if (has_tsig) {
+               /*
+                * Put in the original id.
+                *
+                * XXX Can TCP transfers be forwarded?  How would that
+                * work?
+                */
                id = htons(tsig.originalid);
                memmove(&header[0], &id, 2);
        }
index 8a39936a0a3b0e10ff2a176e6cb105fa0db0fe71..c3029ce97e352429565ef3f676bb4af016acc248 100644 (file)
@@ -177,7 +177,7 @@ linux_if_inet6_current(isc_interfaceiter_t *iter) {
        char address[33];
        char name[IF_NAMESIZE+1];
        struct in6_addr addr6;
-       int ifindex, prefix, flag3, flag4;
+       unsigned int ifindex, prefix, flag3, flag4;
        int res;
        unsigned int i;
 
index e2a556f19d23b4a03bfffd6df7ccd62b0963ea7a..ccade448513e9f3c47428d03f9f3693784ce0cd8 100644 (file)
@@ -1173,8 +1173,6 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id,
        xfr->tsigkey = tsigkey;
        xfr->lasttsig = lasttsig;
        xfr->verified_tsig = verified_tsig;
-       xfr->txmem = NULL;
-       xfr->txmemlen = 0;
        xfr->nmsg = 0;
        xfr->many_answers = many_answers;
        xfr->sends = 0;