From: Ondřej Surý Date: Wed, 25 Mar 2020 16:25:45 +0000 (+0100) Subject: Fix 'Dereference of null pointer' from scan-build-10 X-Git-Tag: v9.14.12~8^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3ba17fedca645fc8d8ca322f794fca72225c63c;p=thirdparty%2Fbind9.git 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: 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 --- diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index 59aa45ee5f7..0ef524a7e99 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -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) { diff --git a/bin/named/main.c b/bin/named/main.c index e4e4d812612..afdb25cae81 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -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; /*