From: Aram Sargsyan Date: Thu, 11 Aug 2022 18:27:11 +0000 (+0000) Subject: Refactor tkey.c:buildquery() error handling X-Git-Tag: v9.19.5~37^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e01162258ed796e68c608c66fff4933893a5c04;p=thirdparty%2Fbind9.git Refactor tkey.c:buildquery() error handling After an earlier code cleanup, `dns_rdatalist_tordataset()` always succeeds, so the `RETERR` error handling macro below the function call was removed. After that change the `dynbuf` variable can never be `NULL` in the error handling code path under the `failure` label. *** CID 355779: Null pointer dereferences (REVERSE_INULL) /lib/dns/tkey.c: 997 in buildquery() 991 dns_message_puttempname(msg, &aname); 992 } 993 if (question != NULL) { 994 dns_rdataset_disassociate(question); 995 dns_message_puttemprdataset(msg, &question); 996 } >>> CID 355779: Null pointer dereferences (REVERSE_INULL) >>> Null-checking "dynbuf" suggests that it may be null, but it has already been dereferenced on all paths leading to the check. 997 if (dynbuf != NULL) { 998 isc_buffer_free(&dynbuf); 999 } 1000 return (result); 1001 } 1002 Refactor the `buildquery()` function to simplify its error handling. --- diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c index a46ac788782..94be0366815 100644 --- a/lib/dns/tkey.c +++ b/lib/dns/tkey.c @@ -940,6 +940,18 @@ buildquery(dns_message_t *msg, const dns_name_t *name, dns_rdata_tkey_t *tkey, REQUIRE(name != NULL); REQUIRE(tkey != NULL); + len = 16 + tkey->algorithm.length + tkey->keylen + tkey->otherlen; + isc_buffer_allocate(msg->mctx, &dynbuf, len); + dns_message_gettemprdata(msg, &rdata); + result = dns_rdata_fromstruct(rdata, dns_rdataclass_any, + dns_rdatatype_tkey, tkey, dynbuf); + if (result != ISC_R_SUCCESS) { + dns_message_puttemprdata(msg, &rdata); + isc_buffer_free(&dynbuf); + return (result); + } + dns_message_takebuffer(msg, &dynbuf); + dns_message_gettempname(msg, &qname); dns_message_gettempname(msg, &aname); @@ -947,14 +959,6 @@ buildquery(dns_message_t *msg, const dns_name_t *name, dns_rdata_tkey_t *tkey, dns_rdataset_makequestion(question, dns_rdataclass_any, dns_rdatatype_tkey); - len = 16 + tkey->algorithm.length + tkey->keylen + tkey->otherlen; - isc_buffer_allocate(msg->mctx, &dynbuf, len); - dns_message_gettemprdata(msg, &rdata); - - RETERR(dns_rdata_fromstruct(rdata, dns_rdataclass_any, - dns_rdatatype_tkey, tkey, dynbuf)); - dns_message_takebuffer(msg, &dynbuf); - dns_message_gettemprdatalist(msg, &tkeylist); tkeylist->rdclass = dns_rdataclass_any; tkeylist->type = dns_rdatatype_tkey; @@ -982,25 +986,6 @@ buildquery(dns_message_t *msg, const dns_name_t *name, dns_rdata_tkey_t *tkey, } return (ISC_R_SUCCESS); - -failure: - if (qname != NULL) { - dns_message_puttempname(msg, &qname); - } - if (aname != NULL) { - dns_message_puttempname(msg, &aname); - } - if (question != NULL) { - dns_rdataset_disassociate(question); - dns_message_puttemprdataset(msg, &question); - } - if (dynbuf != NULL) { - isc_buffer_free(&dynbuf); - } - if (rdata != NULL) { - dns_message_puttemprdata(msg, &rdata); - } - return (result); } isc_result_t