From 2beca482895eebbe7362277f700cb7376b1a6cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 25 Mar 2020 17:00:07 +0100 Subject: [PATCH 1/2] Fix 'Dead nested assignment's from scan-build-10 The 3 warnings reported are: os.c:872:7: warning: Although the value stored to 'ptr' is used in the enclosing expression, the value is never actually read from 'ptr' if ((ptr = strtok_r(command, " \t", &last)) == NULL) { ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. -- rpz.c:1117:10: warning: Although the value stored to 'zbits' is used in the enclosing expression, the value is never actually read from 'zbits' return (zbits &= x); ^ ~ 1 warning generated. -- openssleddsa_link.c:532:10: warning: Although the value stored to 'err' is used in the enclosing expression, the value is never actually read from 'err' while ((err = ERR_get_error()) != 0) { ^ ~~~~~~~~~~~~~~~ 1 warning generated. (cherry picked from commit 262f087bcff969b6eca2ae0a71be4323a3c1729d) (cherry picked from commit 138dded9d92de3fc966494862e8e38ded4467fc9) --- lib/dns/openssleddsa_link.c | 4 ++-- lib/dns/rpz.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/dns/openssleddsa_link.c b/lib/dns/openssleddsa_link.c index c8fb282c01..32bd02ef2b 100644 --- a/lib/dns/openssleddsa_link.c +++ b/lib/dns/openssleddsa_link.c @@ -518,7 +518,6 @@ static bool openssleddsa_isprivate(const dst_key_t *key) { EVP_PKEY *pkey = key->keydata.pkey; int len; - unsigned long err; if (pkey == NULL) return (false); @@ -527,8 +526,9 @@ openssleddsa_isprivate(const dst_key_t *key) { if (len > 0) return (true); /* can check if first error is EC_R_INVALID_PRIVATE_KEY */ - while ((err = ERR_get_error()) != 0) + while (ERR_get_error() != 0) { /**/; + } return (false); } diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index eb4eaaf378..bbd94c70c6 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -1114,7 +1114,8 @@ trim_zbits(dns_rpz_zbits_t zbits, dns_rpz_zbits_t found) { x = zbits & found; x &= (~x + 1); x = (x << 1) - 1; - return (zbits &= x); + zbits &= x; + return (zbits); } /* From 0ff5c1f10d6159ab89cacf93aadcbe15e436c5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 25 Mar 2020 17:25:45 +0100 Subject: [PATCH 2/2] Fix 'Dereference of null pointer' from scan-build-10 These are mostly false positives, the clang-analyzer FAQ[1] specifies why and how to fix it: > The reason the analyzer often thinks that a pointer can be null is > because the preceding code checked compared it against null. So if you > are absolutely sure that it cannot be null, remove the preceding check > and, preferably, add an assertion as well. The 2 warnings reported are: byname_test.c:308:34: warning: Access to field 'fwdtable' results in a dereference of a null pointer (loaded from variable 'view') RUNTIME_CHECK(dns_fwdtable_add(view->fwdtable, dns_rootname, ^~~~~~~~~~~~~~ /builds/isc-projects/bind9/lib/isc/include/isc/util.h:318:52: note: expanded from macro 'RUNTIME_CHECK' ^~~~ /builds/isc-projects/bind9/lib/isc/include/isc/error.h:50:21: note: expanded from macro 'ISC_ERROR_RUNTIMECHECK' ((void)(ISC_LIKELY(cond) || \ ^~~~ /builds/isc-projects/bind9/lib/isc/include/isc/likely.h:23:43: note: expanded from macro 'ISC_LIKELY' ^ 1 warning generated. -- ./rndc.c:255:6: warning: Dereference of null pointer (loaded from variable 'host') if (*host == '/') { ^~~~~ 1 warning generated. References: 1. https://clang-analyzer.llvm.org/faq.html#null_pointer (cherry picked from commit ddd0d356e5922e6b1958b3050e04a160e106734a) (cherry picked from commit 9b76eea08f7c1a205c8269bd7b301a3c45455202) --- bin/rndc/rndc.c | 5 ++++- bin/tests/optional/byname_test.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 48682de9db..63dabad24a 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -249,6 +249,8 @@ get_addresses(const char *host, in_port_t port) { isc_result_t result; int found = 0, count; + REQUIRE(host != NULL); + if (*host == '/') { result = isc_sockaddr_frompath(&serveraddrs[nserveraddrs], host); @@ -990,8 +992,9 @@ main(int argc, char **argv) { if (strcmp(command, "restart") == 0) fatal("'%s' is not implemented", command); - if (nserveraddrs == 0) + if (nserveraddrs == 0 && servername != NULL) { get_addresses(servername, (in_port_t) remoteport); + } DO("post event", isc_app_onrun(rndc_mctx, task, rndc_start, NULL)); diff --git a/bin/tests/optional/byname_test.c b/bin/tests/optional/byname_test.c index c48baec0bd..f515218f47 100644 --- a/bin/tests/optional/byname_test.c +++ b/bin/tests/optional/byname_test.c @@ -312,6 +312,7 @@ main(int argc, char *argv[]) { isc_sockaddr_fromin(&sa, &ina, 53); ISC_LIST_APPEND(sal, &sa, link); + REQUIRE(DNS_VIEW_VALID(view)); RUNTIME_CHECK(dns_fwdtable_add(view->fwdtable, dns_rootname, &sal, dns_fwdpolicy_only) == ISC_R_SUCCESS);