]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Various little fixes found by coccinelle
authorOndřej Surý <ondrej@sury.org>
Mon, 9 Sep 2019 12:05:31 +0000 (14:05 +0200)
committerOndřej Surý <ondrej@sury.org>
Tue, 1 Oct 2019 14:48:55 +0000 (16:48 +0200)
The coccinellery repository provides many little semantic patches to fix common
problems in the code.  The number of semantic patches in the coccinellery
repository is high and most of the semantic patches apply only for Linux, so it
doesn't make sense to run them on regular basis as the processing takes a lot of
time.

The list of issue found in BIND 9, by no means complete, includes:

- double assignment to a variable
- `continue` at the end of the loop
- double checks for `NULL`
- useless checks for `NULL` (cannot be `NULL`, because of earlier return)
- using `0` instead of `NULL`
- useless extra condition (`if (foo) return; if (!foo) { ...; }`)
- removing & in front of static functions passed as arguments

24 files changed:
bin/delv/delv.c
bin/dig/dighost.c
bin/dnssec/dnssec-signzone.c
bin/named/fuzz.c
contrib/dlz/drivers/dlz_bdbhpt_driver.c
contrib/dlz/drivers/dlz_mysql_driver.c
contrib/dlz/drivers/dlz_odbc_driver.c
contrib/dlz/drivers/dlz_postgres_driver.c
contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c
contrib/dlz/modules/common/dlz_dbi.c
contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c
contrib/dlz/modules/mysql/dlz_mysql_dynamic.c
contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c
lib/dns/dnsrps.c
lib/dns/dnstap.c
lib/dns/ds.c
lib/dns/openssldh_link.c
lib/dns/opensslecdsa_link.c
lib/dns/openssleddsa_link.c
lib/dns/opensslrsa_link.c
lib/isc/xoshiro128starstar.c
lib/isccfg/namedconf.c
lib/ns/hooks.c
lib/ns/xfrout.c

index 7155d4b2994fc05eea3c9a4eaa882a28a63d2330..144b26c1f033b36915737e7a1dff04b0c7d87106 100644 (file)
@@ -635,14 +635,12 @@ key_fromconfig(const cfg_obj_t *key, dns_client_t *client) {
        if (!match_root) {
                return (ISC_R_SUCCESS);
        }
-       if (!root_validation && match_root) {
+
+       if (!root_validation) {
                return (ISC_R_SUCCESS);
        }
 
-       if (match_root) {
-               delv_log(ISC_LOG_DEBUG(3), "adding trust anchor %s",
-                         trust_anchor);
-       }
+       delv_log(ISC_LOG_DEBUG(3), "adding trust anchor %s", trust_anchor);
 
        flags = cfg_obj_asuint32(cfg_tuple_get(key, "flags"));
        proto = cfg_obj_asuint32(cfg_tuple_get(key, "protocol"));
index 222b7875bf2c79961604ba06bce48b2cd1b64280..5e24af65e5345f117803a74c9556d0241f9c2de4 100644 (file)
@@ -649,7 +649,6 @@ make_empty_lookup(void) {
        looknew->use_usec = false;
        looknew->nocrypto = false;
        looknew->ttlunits = false;
-       looknew->ttlunits = false;
        looknew->expandaaaa = false;
        looknew->qr = false;
        looknew->accept_reply_unexpected_src = false;
index 5f3cfa9ad41654262aaa1c5f60860bc15eb2acc4..8f3e74cb2c8a27ab709733491e5250696a23b9b2 100644 (file)
@@ -1706,7 +1706,6 @@ remove_records(dns_dbnode_t *node, dns_rdatatype_t which,
                        result = dns_db_deleterdataset(gdb, node, gversion,
                                                       type, covers);
                        check_result(result, "dns_db_deleterdataset()");
-                       continue;
                }
        }
        dns_rdatasetiter_destroy(&rdsiter);
@@ -3583,7 +3582,6 @@ main(int argc, char *argv[]) {
                        outputformat = dns_masterformat_raw;
                } else if (strncasecmp(outputformatstr, "raw=", 4) == 0) {
                        char *end;
-                       outputformat = dns_masterformat_raw;
 
                        outputformat = dns_masterformat_raw;
                        rawversion = strtol(outputformatstr + 4, &end, 10);
index 02c75d303aa0d8e75ffb9a1573d07c144edb94f8..0064d920755f8d49cfc1f036e5f6618a43083628 100644 (file)
@@ -142,7 +142,7 @@ fuzz_thread_client(void *arg) {
                 * Read the reply message from named to unclog it. Don't
                 * bother if there isn't a reply.
                 */
-               recvfrom(sockfd, buf, 65536, MSG_DONTWAIT, NULL, NULL);
+               (void)recvfrom(sockfd, buf, 65536, MSG_DONTWAIT, NULL, NULL);
 
                while (!ready)
                        pthread_cond_wait(&cond, &mutex);
@@ -412,8 +412,8 @@ fuzz_thread_resolver(void *arg) {
                 * Flush any pending data on the authoritative server.
                 */
                socklen = sizeof(recvaddr);
-               sent = recvfrom(listenfd, rbuf, 65536, MSG_DONTWAIT,
-                       (struct sockaddr *) &recvaddr, &socklen);
+               (void)recvfrom(listenfd, rbuf, 65536, MSG_DONTWAIT,
+                              (struct sockaddr *) &recvaddr, &socklen);
 
                /*
                 * Send a fixed client query to named(resolver) of
@@ -511,7 +511,8 @@ fuzz_thread_resolver(void *arg) {
                                 * to the client(query driver), so we're
                                 * done.
                                 */
-                               recvfrom(sockfd, buf, 65536, 0, NULL, NULL);
+                               (void)recvfrom(sockfd, buf, 65536, 0, NULL,
+                                              NULL);
                                break;
                        }
 
index 1f200158608623380d6695e2af1dbac215503337..4d3d93560759e8ca46f09457c58fc45a8aa09b99 100644 (file)
@@ -591,8 +591,7 @@ bdbhpt_lookup(const char *zone, const char *name, void *driverarg,
        if (data_cursor != NULL)
                data_cursor->c_close(data_cursor);
 
-       if (keyStr != NULL)
-               free(keyStr);
+       free(keyStr);
        if (tmp != NULL)
                free(tmp);
 
index da1c9393c015d88e2de9a66cb2b47e5456b803e7..5e4366dac5a724c976be0d4f5785e98ea0df77f8 100644 (file)
@@ -138,8 +138,7 @@ mysql_get_resultset(const char *zone, const char *record,
 
        /* if DBI is null, can't do anything else */
        if (dbi == NULL) {
-               result = ISC_R_FAILURE;
-               goto cleanup;
+               return (ISC_R_FAILURE);
        }
 
        /* what type of query are we going to run? */
@@ -330,10 +329,6 @@ mysql_get_resultset(const char *zone, const char *record,
  cleanup:
        /* it's always good to cleanup after yourself */
 
-       /* if we couldn't even get DBI, just return NULL */
-       if (dbi == NULL)
-               return ISC_R_FAILURE;
-
        /* free dbi->zone string */
        if (dbi->zone != NULL)
                isc_mem_free(named_g_mctx, dbi->zone);
index c5a1a156f3fffbbab78a379a0ac721e9f61e551b..59e31441e06f05c7e2bc82349e057069543157c8 100644 (file)
@@ -35,7 +35,7 @@
 
 /*
  * Copyright (C) 1999-2001, 2016  Internet Systems Consortium, Inc. ("ISC")
- * 
+ *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -433,8 +433,7 @@ odbc_get_resultset(const char *zone, const char *record,
 
        /* if DBI is null, can't do anything else */
        if (dbi == NULL) {
-               result = ISC_R_FAILURE;
-               goto cleanup;
+               return (ISC_R_FAILURE);
        }
 
        /* what type of query are we going to run? */
@@ -616,10 +615,6 @@ odbc_get_resultset(const char *zone, const char *record,
 
  cleanup:      /* it's always good to cleanup after yourself */
 
-               /* if we couldn't even allocate DBI, just return NULL */
-       if (dbi == NULL)
-               return ISC_R_FAILURE;
-
        /* free dbi->zone string */
        if (dbi->zone != NULL)
                isc_mem_free(named_g_mctx, dbi->zone);
index 3bd72b59eec6271983b9e7161bb5cd47f8586aec..ec6fd93686dccf90f8b763c57fc3d49db3be16fd 100644 (file)
@@ -303,8 +303,7 @@ postgres_get_resultset(const char *zone, const char *record,
 
        /* if DBI is null, can't do anything else */
        if (dbi == NULL) {
-               result = ISC_R_FAILURE;
-               goto cleanup;
+               return (ISC_R_FAILURE);
        }
 
        /* what type of query are we going to run? */
@@ -564,10 +563,6 @@ postgres_get_resultset(const char *zone, const char *record,
                      "%d cleaning up", dlz_thread_num);
 #endif
 
-       /* if we couldn't even allocate DBI, just return NULL */
-       if (dbi == NULL)
-               return ISC_R_FAILURE;
-
        /* free dbi->zone string */
        if (dbi->zone != NULL)
                isc_mem_free(named_g_mctx, dbi->zone);
index 43e54f979202b8f5328689fa808e16378e60f13c..859605f63c695d2ab58ae22bdebf92bab54703e9 100644 (file)
@@ -594,8 +594,7 @@ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata,
        if (data_cursor != NULL)
                data_cursor->c_close(data_cursor);
        
-       if (keyStr != NULL)
-               free(keyStr);
+       free(keyStr);
        if (tmp != NULL)
                free(tmp);
        
index 7b4c9da5f0baf6e5034255bf91a03c69e39ef308..e4c27bb7464efeca3f0d36fe0c6fe33e5af52ca4 100644 (file)
@@ -255,8 +255,7 @@ build_querylist(const char *query_str, char **zone, char **record,
 
  flag_fail:
        /* get rid of what was build of the query list */
-       if (tql != NULL)
-               destroy_querylist(&tql);
+       destroy_querylist(&tql);
        return (result);
 }
 
index 494bd1805a05ebecb1593bff8abda715d6cfdf16..a143fd5e96c09c273e8aa02c00b95668ba291f39 100644 (file)
@@ -595,7 +595,6 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
        dir_entry_t *next_de;
 
        basepath = NULL;
-       dir_list = NULL;
 
        /* allocate memory for list */
        dir_list = malloc(sizeof(dlist_t));
index a325fc5d2257f3304a0f9949f40dcabdcea8aaf3..84ab45f6e0b422c74880f1f5df861388f5b06acf 100644 (file)
@@ -246,8 +246,7 @@ mysql_get_resultset(const char *zone, const char *record,
 #endif /* PTHREADS */
 
        if (dbi == NULL) {
-               result = ISC_R_FAILURE;
-               goto cleanup;
+               return (ISC_R_FAILURE);
        }
 
        /* what type of query are we going to run? */
@@ -401,9 +400,6 @@ mysql_get_resultset(const char *zone, const char *record,
                result = ISC_R_FAILURE;
 
  cleanup:
-       if (dbi == NULL)
-               return (ISC_R_FAILURE);
-
        if (dbi->zone != NULL) {
                free(dbi->zone);
                dbi->zone = NULL;
index 2d7d0b0675016afd1be142ae24d7b7568effdf58..caf519f5d5bfd0d80573af3db132da494798c59f 100644 (file)
@@ -35,7 +35,7 @@
 
 /*
  * Copyright (C) 1999-2001, 2013-2014, 2016  Internet Systems Consortium, Inc. ("ISC")
- * 
+ *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -277,8 +277,7 @@ sqlite3_get_resultset(const char *zone, const char *record,
 #endif /* PTHREADS */
 
        if (dbi == NULL) {
-               result = ISC_R_FAILURE;
-               goto cleanup;
+               return (ISC_R_FAILURE);
        }
 
        /* what type of query are we going to run? */
@@ -431,16 +430,13 @@ sqlite3_get_resultset(const char *zone, const char *record,
        result = ISC_R_SUCCESS;
        if (query == COUNTZONE) {
                sqlite3_free_table(rs->pazResult);
-               if (rs == NULL)
-                       result = ISC_R_FAILURE;
        }
 
-       *rsp = rs;
+       if (rsp != NULL) {
+               *rsp = rs;
+       }
 
  cleanup:
-       if (dbi == NULL)
-               return (ISC_R_FAILURE);
-
        if (dbi->zone != NULL) {
                free(dbi->zone);
                dbi->zone = NULL;
index 7ecc53f1c0a56c2c8abf0ac866c4796beb3cc7f6..c4f68e15b341d9d017dd197ea442a0fb3134745c 100644 (file)
@@ -146,7 +146,7 @@ dns_dnsrps_server_create(void) {
 
        isc_mutex_init(&dnsrps_mutex);
 
-       librpz->set_log(&dnsrps_log_fnc, NULL);
+       librpz->set_log(dnsrps_log_fnc, NULL);
 
        clist = librpz->clist_create(&emsg, dnsrps_lock, dnsrps_unlock,
                                     dnsrps_mutex_destroy, &dnsrps_mutex,
index 7a4a01ea609850eadf6726395d51f27475da2fde..4e7d8e7b4817b5681cac6a8bbf19a95b9650c279 100644 (file)
@@ -266,14 +266,17 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path,
        *envp = env;
 
  cleanup:
-       if (ffwopt != NULL)
+       if (ffwopt != NULL) {
                fstrm_file_options_destroy(&ffwopt);
+       }
 
-       if (fuwopt != NULL)
+       if (fuwopt != NULL) {
                fstrm_unix_writer_options_destroy(&fuwopt);
+       }
 
-       if (fwopt != NULL)
+       if (fwopt != NULL) {
                fstrm_writer_options_destroy(&fwopt);
+       }
 
        if (result != ISC_R_SUCCESS) {
                isc_mutex_destroy(&env->reopen_lock);
@@ -337,8 +340,7 @@ dns_dt_reopen(dns_dtenv_t *env, int roll) {
         */
        fwopt = fstrm_writer_options_init();
        if (fwopt == NULL) {
-               isc_task_endexclusive(env->reopen_task);
-               return (ISC_R_NOMEMORY);
+               CHECK(ISC_R_NOMEMORY);
        }
 
        res = fstrm_writer_options_add_content_type(fwopt,
@@ -414,17 +416,21 @@ dns_dt_reopen(dns_dtenv_t *env, int roll) {
        }
 
  cleanup:
-       if (ffwopt != NULL)
-               fstrm_file_options_destroy(&ffwopt);
-
-       if (fw != NULL)
+       if (fw != NULL) {
                fstrm_writer_destroy(&fw);
+       }
 
-       if (fwopt != NULL)
-               fstrm_writer_options_destroy(&fwopt);
-
-       if (fuwopt != NULL)
+       if (fuwopt != NULL) {
                fstrm_unix_writer_options_destroy(&fuwopt);
+       }
+
+       if (ffwopt != NULL) {
+               fstrm_file_options_destroy(&ffwopt);
+       }
+
+       if (fwopt != NULL) {
+               fstrm_writer_options_destroy(&fwopt);
+       }
 
        isc_task_endexclusive(env->reopen_task);
 
index 857afe7ef21da5dae335e2242c347c7d2ed2721b..8958fb89cf2b4fa98d28efe7341fc6997608bb50 100644 (file)
@@ -118,8 +118,6 @@ dns_ds_buildrdata(dns_name_t *owner, dns_rdata_t *key,
        ret = dns_rdata_fromstruct(rdata, key->rdclass, dns_rdatatype_ds,
                                   &ds, &b);
 end:
-       if (md != NULL) {
-               isc_md_free(md);
-       }
+       isc_md_free(md);
        return (ret);
 }
index 7f9c244c6a18e8af68a7bedeb6607bebcff11450..ff14c7e9563568ea912bcd1e130effa1ff4156b1 100644 (file)
@@ -306,7 +306,7 @@ openssldh_generate(dst_key_t *key, int generator, void (*callback)(int)) {
                } else {
                        /* cppcheck-suppress unreadVariable */
                        u.fptr = callback;
-                       BN_GENCB_set(cb, &progress_cb, u.dptr);
+                       BN_GENCB_set(cb, progress_cb, u.dptr);
                }
 
                if (!DH_generate_parameters_ex(dh, key->key_size, generator,
index 895f16da45fa9d47af1a13b2497619d6640800a8..04cef6dbdaa77e00b77c6d99f45e36260ace02e3 100644 (file)
@@ -186,8 +186,7 @@ opensslecdsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
        ret = ISC_R_SUCCESS;
 
  err:
-       if (eckey != NULL)
-               EC_KEY_free(eckey);
+       EC_KEY_free(eckey);
        return (ret);
 }
 
@@ -251,8 +250,7 @@ opensslecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
  err:
        if (ecdsasig != NULL)
                ECDSA_SIG_free(ecdsasig);
-       if (eckey != NULL)
-               EC_KEY_free(eckey);
+       EC_KEY_free(eckey);
        return (ret);
 }
 
@@ -340,8 +338,7 @@ opensslecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) {
        ret = ISC_R_SUCCESS;
 
  err:
-       if (eckey != NULL)
-               EC_KEY_free(eckey);
+       EC_KEY_free(eckey);
        return (ret);
 }
 
@@ -396,8 +393,7 @@ opensslecdsa_todns(const dst_key_t *key, isc_buffer_t *data) {
        ret = ISC_R_SUCCESS;
 
  err:
-       if (eckey != NULL)
-               EC_KEY_free(eckey);
+       EC_KEY_free(eckey);
        return (ret);
 }
 
@@ -497,8 +493,7 @@ opensslecdsa_tofile(const dst_key_t *key, const char *directory) {
        ret = dst__privstruct_writefile(key, &priv, directory);
 
  err:
-       if (eckey != NULL)
-               EC_KEY_free(eckey);
+       EC_KEY_free(eckey);
        if (buf != NULL)
                isc_mem_put(key->mctx, buf, BN_num_bytes(privkey));
        return (ret);
@@ -529,8 +524,7 @@ ecdsa_check(EC_KEY *eckey, dst_key_t *pub)
                DST_RET (ISC_R_SUCCESS);
 
  err:
-       if (pubeckey != NULL)
-               EC_KEY_free(pubeckey);
+       EC_KEY_free(pubeckey);
        return (ret);
 }
 
index 8357bee05840e3873933fedc40ca56b7168711ec..717e9eaa82174cc61c4614313575da3f2046c3e1 100644 (file)
@@ -367,8 +367,7 @@ openssleddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
        ret = ISC_R_SUCCESS;
 
  err:
-       if (ctx != NULL)
-               EVP_MD_CTX_free(ctx);
+       EVP_MD_CTX_free(ctx);
        isc_buffer_free(&buf);
        dctx->ctxdata.generic = NULL;
 
@@ -435,8 +434,7 @@ openssleddsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
        }
 
  err:
-       if (ctx != NULL)
-               EVP_MD_CTX_free(ctx);
+       EVP_MD_CTX_free(ctx);
        isc_buffer_free(&buf);
        dctx->ctxdata.generic = NULL;
 
@@ -507,8 +505,7 @@ openssleddsa_generate(dst_key_t *key, int unused, void (*callback)(int)) {
        ret = ISC_R_SUCCESS;
 
  err:
-       if (ctx != NULL)
-               EVP_PKEY_CTX_free(ctx);
+       EVP_PKEY_CTX_free(ctx);
        return (ret);
 }
 
index ecf13c7625b11bd9eee809b69167f46ca4086ab6..1a61c9f366a42f434bad857a26d7a1b3bb797221 100644 (file)
@@ -497,7 +497,7 @@ opensslrsa_generate(dst_key_t *key, int exp, void (*callback)(int)) {
        } else {
                /* cppcheck-suppress unreadVariable */
                u.fptr = callback;
-               BN_GENCB_set(cb, &progress_cb, u.dptr);
+               BN_GENCB_set(cb, progress_cb, u.dptr);
        }
 
        if (RSA_generate_key_ex(rsa, key->key_size, e, cb)) {
@@ -600,8 +600,7 @@ opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data) {
 
        ret = ISC_R_SUCCESS;
  err:
-       if (rsa != NULL)
-               RSA_free(rsa);
+       RSA_free(rsa);
        return (ret);
 }
 
index 0882041a749cd75d68fd00d9a45f693e50fbec70..abf1ea8455957301a39dfefc209ee39012b0a902 100644 (file)
@@ -50,7 +50,7 @@ static __declspec( thread ) uint32_t seed[4];
 #else
 #if defined(_WIN32) || defined(_WIN64)
 #include <windows.h>
-static volatile HANDLE _mutex = NULL;
+static volatile void *_mutex = NULL;
 
 /*
  * Initialize the mutex on the first lock attempt. On collision, each thread
@@ -60,7 +60,7 @@ static volatile HANDLE _mutex = NULL;
 #define _LOCK() \
        do {                                                            \
                if (!_mutex) {                                          \
-                       HANDLE p = CreateMutex(NULL, FALSE, NULL);      \
+                       void *p = CreateMutex(NULL, FALSE, NULL);       \
                        if (InterlockedCompareExchangePointer           \
                            ((void **)&_mutex, (void *)p, NULL)) {      \
                                CloseHandle(p);                         \
index b6c70e4bc6d75080f20aa2b8e8dfb03b3334374a..d427ec488d9ba79d445df53a96b1c1d786233d6f 100644 (file)
@@ -312,7 +312,7 @@ static cfg_type_t cfg_type_matchtype = {
 
 static cfg_type_t cfg_type_matchname = {
        "optional_matchname", parse_matchname, cfg_print_ustring,
-       &doc_matchname, &cfg_rep_tuple, &cfg_type_ustring
+       doc_matchname, &cfg_rep_tuple, &cfg_type_ustring
 };
 
 /*%
index d89a063ad2e2dc2ea7c7ca6a3fa3610d4a0b8f21..8a60042c51a7589397c129652daffa52795cf97b 100644 (file)
@@ -211,9 +211,7 @@ cleanup:
                                             sizeof(*plugin));
                }
 
-               if (handle != NULL) {
-                       (void) dlclose(handle);
-               }
+               (void) dlclose(handle);
        }
 
        return (result);
index 55609bbbaae54471d0dbffc7de8f23ff9e9b1685..7672f59d9a52b1fd362657e76d494fca05bf2564 100644 (file)
@@ -279,7 +279,7 @@ ixfr_rrstream_current(rrstream_t *rs,
 static void
 ixfr_rrstream_destroy(rrstream_t **rsp) {
        ixfr_rrstream_t *s = (ixfr_rrstream_t *) *rsp;
-       if (s->journal != 0)
+       if (s->journal != NULL)
                dns_journal_destroy(&s->journal);
        isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s));
 }