]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix 'Dereference of null pointer' from scan-build-10
authorOndřej Surý <ondrej@isc.org>
Wed, 25 Mar 2020 16:25:45 +0000 (17:25 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 25 Mar 2020 17:27:08 +0000 (18:27 +0100)
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
bin/tests/optional/byname_test.c

index 48682de9db2c1dba9a2b9255677df96ce28eabc8..63dabad24afe32fc66edde7bf6b13375c9bdff38 100644 (file)
@@ -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));
 
index c48baec0bd1deb1083ae687b0cfc6935fae49502..f515218f476c9c73a873f94d2a8299d72b6125c7 100644 (file)
@@ -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);