mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 10:10:06 +00:00
Various little fixes found by coccinelle
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
This commit is contained in:
parent
c2e8a111f5
commit
288f5a4b52
@ -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"));
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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); \
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
/*%
|
||||
|
@ -211,9 +211,7 @@ cleanup:
|
||||
sizeof(*plugin));
|
||||
}
|
||||
|
||||
if (handle != NULL) {
|
||||
(void) dlclose(handle);
|
||||
}
|
||||
(void) dlclose(handle);
|
||||
}
|
||||
|
||||
return (result);
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user