]> 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>
Thu, 26 Mar 2020 12:42:35 +0000 (13:42 +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:

dnssec-cds.c:781:4: warning: Access to field 'base' results in a dereference of a null pointer (loaded from variable 'buf')
                        isc_buffer_availableregion(buf, &r);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/isc-projects/bind9/lib/isc/include/isc/buffer.h:996:36: note: expanded from macro 'isc_buffer_availableregion'
                                   ^
/builds/isc-projects/bind9/lib/isc/include/isc/buffer.h:821:16: note: expanded from macro 'ISC__BUFFER_AVAILABLEREGION'
                (_r)->base = isc_buffer_used(_b);              \
                             ^~~~~~~~~~~~~~~~~~~
/builds/isc-projects/bind9/lib/isc/include/isc/buffer.h:152:29: note: expanded from macro 'isc_buffer_used'
        ((void *)((unsigned char *)(b)->base + (b)->used)) /*d*/
                                   ^~~~~~~~~
1 warning generated.

--

./main.c:1254:9: warning: Access to field 'sctx' results in a dereference of a null pointer (loaded from variable 'named_g_server')
        sctx = named_g_server->sctx;
               ^~~~~~~~~~~~~~~~~~~~
1 warning generated.

References:
1. https://clang-analyzer.llvm.org/faq.html#null_pointer

bin/dnssec/dnssec-cds.c
bin/named/main.c

index 59aa45ee5f7b6f05f94c64786f3299653cd29c9e..0ef524a7e9987be427d53c2f6c1a81089ffa47a8 100644 (file)
@@ -788,6 +788,8 @@ ds_from_cds(dns_rdatalist_t *dslist, isc_buffer_t *buf, dns_rdata_t *cds) {
        dns_rdata_ds_t ds;
        dns_rdata_t *rdata;
 
+       REQUIRE(buf != NULL);
+
        rdata = rdata_get();
 
        result = dns_rdata_tostruct(cds, &ds, NULL);
@@ -807,6 +809,8 @@ ds_from_cdnskey(dns_rdatalist_t *dslist, isc_buffer_t *buf,
        isc_result_t result;
        unsigned i, n;
 
+       REQUIRE(buf != NULL);
+
        n = sizeof(dtype)/sizeof(dtype[0]);
        for (i = 0; i < n; i++) {
                if (dtype[i] != 0) {
index e4e4d812612169fdb9240fcf856452339288a653..afdb25cae81f0afe7b6595d4562525f18e98af7a 100644 (file)
@@ -1229,6 +1229,7 @@ setup(void) {
 #endif
 
        named_server_create(named_g_mctx, &named_g_server);
+       ENSURE(named_g_server != NULL);
        sctx = named_g_server->sctx;
 
        /*