From 9ffb4a7ba11fae64a6ce2dd6390cd334372b7ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Fri, 10 Jun 2022 14:30:23 +0200 Subject: [PATCH 1/4] Remove NULL checks for ns_client_newrdataset() ns_client_newrdataset() cannot fail (i.e. return NULL) since commit efb385ecdcfd3213b3bb739a3dcb9e431690e559 (though it was only made more apparent by commit 33ba0057a7c44d4e5d63f7f55e1823279e996a19). Remove redundant NULL checks performed on the pointer returned by ns_client_newrdataset(). --- lib/ns/query.c | 122 +++---------------------------------------------- 1 file changed, 7 insertions(+), 115 deletions(-) diff --git a/lib/ns/query.c b/lib/ns/query.c index 5e924438ae..4c53558731 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -1716,14 +1716,11 @@ query_additional_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype, } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); - if (fname == NULL || rdataset == NULL) { + if (fname == NULL) { goto cleanup; } if (WANTDNSSEC(client)) { sigrdataset = ns_client_newrdataset(client); - if (sigrdataset == NULL) { - goto cleanup; - } } /* @@ -1765,9 +1762,6 @@ query_additional_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype, */ if (sigrdataset == NULL) { sigrdataset = ns_client_newrdataset(client); - if (sigrdataset == NULL) { - goto cleanup; - } } version = NULL; @@ -1898,9 +1892,6 @@ found: } } else { rdataset = ns_client_newrdataset(client); - if (rdataset == NULL) { - goto addname; - } } if (sigrdataset != NULL) { if (dns_rdataset_isassociated(sigrdataset)) { @@ -1908,9 +1899,6 @@ found: } } else if (WANTDNSSEC(client)) { sigrdataset = ns_client_newrdataset(client); - if (sigrdataset == NULL) { - goto addname; - } } if (query_isduplicate(client, fname, dns_rdatatype_a, NULL)) { goto aaaa_lookup; @@ -1966,12 +1954,6 @@ found: ns_client_newrdataset(client); } rdataset = ns_client_newrdataset(client); - if (rdataset == NULL) { - goto addname; - } - if (WANTDNSSEC(client) && sigrdataset == NULL) { - goto addname; - } } else { dns_rdataset_disassociate(rdataset); if (sigrdataset != NULL && @@ -2576,9 +2558,6 @@ query_prefetch(ns_client_t *client, dns_name_t *qname, ns_statscounter_recursclients); tmprdataset = ns_client_newrdataset(client); - if (tmprdataset == NULL) { - return; - } if (!TCP(client)) { peeraddr = &client->peeraddr; @@ -2637,11 +2616,6 @@ rpz_ready(ns_client_t *client, dns_rdataset_t **rdatasetp) { if (*rdatasetp == NULL) { *rdatasetp = ns_client_newrdataset(client); - if (*rdatasetp == NULL) { - CTRACE(ISC_LOG_ERROR, "rpz_ready: " - "ns_client_newrdataset failed"); - return (DNS_R_SERVFAIL); - } } else if (dns_rdataset_isassociated(*rdatasetp)) { dns_rdataset_disassociate(*rdatasetp); } @@ -2796,9 +2770,6 @@ query_rpzfetch(ns_client_t *client, dns_name_t *qname, dns_rdatatype_t type) { ns_statscounter_recursclients); tmprdataset = ns_client_newrdataset(client); - if (tmprdataset == NULL) { - return; - } if (!TCP(client)) { peeraddr = &client->peeraddr; @@ -5736,35 +5707,14 @@ qctx_prepare_buffers(query_ctx_t *qctx, isc_buffer_t *buffer) { } qctx->rdataset = ns_client_newrdataset(qctx->client); - if (qctx->rdataset == NULL) { - CCTRACE(ISC_LOG_ERROR, - "qctx_prepare_buffers: ns_client_newrdataset failed"); - goto error; - } if ((WANTDNSSEC(qctx->client) || qctx->findcoveringnsec) && (!qctx->is_zone || dns_db_issecure(qctx->db))) { qctx->sigrdataset = ns_client_newrdataset(qctx->client); - if (qctx->sigrdataset == NULL) { - CCTRACE(ISC_LOG_ERROR, - "qctx_prepare_buffers: " - "ns_client_newrdataset failed (2)"); - goto error; - } } return (ISC_R_SUCCESS); - -error: - if (qctx->fname != NULL) { - ns_client_releasename(qctx->client, &qctx->fname); - } - if (qctx->rdataset != NULL) { - ns_client_putrdataset(qctx->client, &qctx->rdataset); - } - - return (ISC_R_NOMEMORY); } /* @@ -6486,16 +6436,9 @@ ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname, REQUIRE(client->query.fetch == NULL); rdataset = ns_client_newrdataset(client); - if (rdataset == NULL) { - return (ISC_R_NOMEMORY); - } if (WANTDNSSEC(client)) { sigrdataset = ns_client_newrdataset(client); - if (sigrdataset == NULL) { - ns_client_putrdataset(client, &rdataset); - return (ISC_R_NOMEMORY); - } } else { sigrdataset = NULL; } @@ -7754,7 +7697,7 @@ query_addnoqnameproof(query_ctx_t *qctx) { fname = ns_client_newname(client, dbuf, &b); neg = ns_client_newrdataset(client); negsig = ns_client_newrdataset(client); - if (fname == NULL || neg == NULL || negsig == NULL) { + if (fname == NULL) { goto cleanup; } @@ -7788,7 +7731,7 @@ query_addnoqnameproof(query_ctx_t *qctx) { dns_rdataset_disassociate(negsig); } - if (fname == NULL || neg == NULL || negsig == NULL) { + if (fname == NULL) { goto cleanup; } result = dns_rdataset_getclosest(qctx->noqname, fname, neg, negsig); @@ -7951,9 +7894,6 @@ query_respond_any(query_ctx_t *qctx) { } qctx->rdataset = ns_client_newrdataset(qctx->client); - if (qctx->rdataset == NULL) { - break; - } } else { /* * We're not interested in this rdataset. @@ -9029,9 +8969,6 @@ query_addds(query_ctx_t *qctx) { */ rdataset = ns_client_newrdataset(client); sigrdataset = ns_client_newrdataset(client); - if (rdataset == NULL || sigrdataset == NULL) { - goto cleanup; - } /* * Look for the DS record, which may or may not be present. @@ -9793,10 +9730,6 @@ query_synthwildcard(query_ctx_t *qctx, dns_rdataset_t *rdataset, dns_name_copy(qctx->client->query.qname, name); cloneset = ns_client_newrdataset(qctx->client); - if (cloneset == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dns_rdataset_clone(rdataset, cloneset); /* @@ -9804,10 +9737,6 @@ query_synthwildcard(query_ctx_t *qctx, dns_rdataset_t *rdataset, */ if (WANTDNSSEC(qctx->client)) { clonesigset = ns_client_newrdataset(qctx->client); - if (clonesigset == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dns_rdataset_clone(sigrdataset, clonesigset); sigrdatasetp = &clonesigset; } else { @@ -9975,10 +9904,6 @@ query_synthnxdomainnodata(query_ctx_t *qctx, bool nodata, dns_name_t *nowild, cloneset = ns_client_newrdataset(qctx->client); clonesigset = ns_client_newrdataset(qctx->client); - if (cloneset == NULL || clonesigset == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dns_rdataset_clone(nowildrdataset, cloneset); dns_rdataset_clone(signowildrdataset, clonesigset); @@ -10146,9 +10071,6 @@ query_coveringnsec(query_ctx_t *qctx) { soardataset = ns_client_newrdataset(qctx->client); sigsoardataset = ns_client_newrdataset(qctx->client); - if (soardataset == NULL || sigsoardataset == NULL) { - goto cleanup; - } /* * Look for SOA record to construct NODATA response. @@ -10266,9 +10188,6 @@ query_coveringnsec(query_ctx_t *qctx) { soardataset = ns_client_newrdataset(qctx->client); sigsoardataset = ns_client_newrdataset(qctx->client); - if (soardataset == NULL || sigsoardataset == NULL) { - goto cleanup; - } /* * Look for SOA record to construct NXDOMAIN response. @@ -10819,18 +10738,8 @@ query_addsoa(query_ctx_t *qctx, unsigned int override_ttl, dns_name_clone(dns_db_origin(qctx->db), name); rdataset = ns_client_newrdataset(client); - if (rdataset == NULL) { - CTRACE(ISC_LOG_ERROR, "unable to allocate rdataset"); - eresult = DNS_R_SERVFAIL; - goto cleanup; - } if (WANTDNSSEC(client) && dns_db_issecure(qctx->db)) { sigrdataset = ns_client_newrdataset(client); - if (sigrdataset == NULL) { - CTRACE(ISC_LOG_ERROR, "unable to allocate sigrdataset"); - eresult = DNS_R_SERVFAIL; - goto cleanup; - } } /* @@ -10903,7 +10812,6 @@ query_addsoa(query_ctx_t *qctx, unsigned int override_ttl, section); } -cleanup: ns_client_putrdataset(client, &rdataset); if (sigrdataset != NULL) { ns_client_putrdataset(client, &sigrdataset); @@ -10950,21 +10858,9 @@ query_addns(query_ctx_t *qctx) { dns_message_gettempname(client->message, &name); dns_name_clone(dns_db_origin(qctx->db), name); rdataset = ns_client_newrdataset(client); - if (rdataset == NULL) { - CTRACE(ISC_LOG_ERROR, "query_addns: ns_client_newrdataset " - "failed"); - eresult = DNS_R_SERVFAIL; - goto cleanup; - } if (WANTDNSSEC(client) && dns_db_issecure(qctx->db)) { sigrdataset = ns_client_newrdataset(client); - if (sigrdataset == NULL) { - CTRACE(ISC_LOG_ERROR, "query_addns: " - "ns_client_newrdataset failed"); - eresult = DNS_R_SERVFAIL; - goto cleanup; - } } /* @@ -10999,7 +10895,6 @@ query_addns(query_ctx_t *qctx) { DNS_SECTION_AUTHORITY); } -cleanup: CTRACE(ISC_LOG_DEBUG(3), "query_addns: cleanup"); ns_client_putrdataset(client, &rdataset); if (sigrdataset != NULL) { @@ -11060,7 +10955,7 @@ db_find: } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); - if (fname == NULL || rdataset == NULL) { + if (fname == NULL) { goto cleanup; } @@ -11070,9 +10965,6 @@ db_find: */ if (WANTDNSSEC(client) || !is_zone) { sigrdataset = ns_client_newrdataset(client); - if (sigrdataset == NULL) { - goto cleanup; - } } /* @@ -11314,7 +11206,7 @@ again: fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); sigrdataset = ns_client_newrdataset(client); - if (fname == NULL || rdataset == NULL || sigrdataset == NULL) { + if (fname == NULL) { goto cleanup; } @@ -11385,7 +11277,7 @@ again: dns_rdataset_disassociate(sigrdataset); } - if (fname == NULL || rdataset == NULL || sigrdataset == NULL) { + if (fname == NULL) { goto cleanup; } /* @@ -11434,7 +11326,7 @@ again: dns_rdataset_disassociate(sigrdataset); } - if (fname == NULL || rdataset == NULL || sigrdataset == NULL) { + if (fname == NULL) { goto cleanup; } /* From a22923601990088d21c764333948a3c8cef36435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Fri, 10 Jun 2022 14:30:23 +0200 Subject: [PATCH 2/4] Remove NULL checks for ns_client_newname() ns_client_newname() cannot fail (i.e. return NULL) since commit 2ce0de699528c8d505adfde37a916b1742e5562f (though it was only made more apparent by commit 33ba0057a7c44d4e5d63f7f55e1823279e996a19). Remove redundant NULL checks performed on the pointer returned by ns_client_newname(). --- lib/ns/query.c | 67 -------------------------------------------------- 1 file changed, 67 deletions(-) diff --git a/lib/ns/query.c b/lib/ns/query.c index 4c53558731..2f72f71b4f 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -1716,9 +1716,6 @@ query_additional_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype, } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); - if (fname == NULL) { - goto cleanup; - } if (WANTDNSSEC(client)) { sigrdataset = ns_client_newrdataset(client); } @@ -5699,13 +5696,6 @@ qctx_prepare_buffers(query_ctx_t *qctx, isc_buffer_t *buffer) { } qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, buffer); - if (qctx->fname == NULL) { - CCTRACE(ISC_LOG_ERROR, - "qctx_prepare_buffers: ns_client_newname failed"); - - return (ISC_R_NOMEMORY); - } - qctx->rdataset = ns_client_newrdataset(qctx->client); if ((WANTDNSSEC(qctx->client) || qctx->findcoveringnsec) && @@ -6646,12 +6636,6 @@ query_resume(query_ctx_t *qctx) { } qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, &b); - if (qctx->fname == NULL) { - CCTRACE(ISC_LOG_ERROR, "query_resume: ns_client_newname failed " - "(1)"); - QUERY_ERROR(qctx, ISC_R_NOMEMORY); - return (ns_query_done(qctx)); - } if (qctx->rpz_st != NULL && (qctx->rpz_st->state & DNS_RPZ_RECURSING) != 0) { @@ -7697,9 +7681,6 @@ query_addnoqnameproof(query_ctx_t *qctx) { fname = ns_client_newname(client, dbuf, &b); neg = ns_client_newrdataset(client); negsig = ns_client_newrdataset(client); - if (fname == NULL) { - goto cleanup; - } result = dns_rdataset_getnoqname(qctx->noqname, fname, neg, negsig); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -7731,9 +7712,6 @@ query_addnoqnameproof(query_ctx_t *qctx) { dns_rdataset_disassociate(negsig); } - if (fname == NULL) { - goto cleanup; - } result = dns_rdataset_getclosest(qctx->noqname, fname, neg, negsig); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -9135,13 +9113,6 @@ query_nodata(query_ctx_t *qctx, isc_result_t res) { } qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, &b); - if (qctx->fname == NULL) { - CCTRACE(ISC_LOG_ERROR, "query_nodata: " - "ns_client_newname " - "failed (3)"); - QUERY_ERROR(qctx, ISC_R_NOMEMORY); - return (ns_query_done(qctx)); - } } dns_name_copy(qctx->client->query.qname, qctx->fname); qctx->dns64 = false; @@ -9396,9 +9367,6 @@ query_addnxrrsetnsec(query_ctx_t *qctx) { } fname = ns_client_newname(client, dbuf, &b); - if (fname == NULL) { - return; - } dns_name_split(qctx->fname, sig.labels + 1, NULL, fname); /* This will succeed, since we've stripped labels. */ @@ -9657,11 +9625,6 @@ query_synthnodata(query_ctx_t *qctx, const dns_name_t *signer, } name = ns_client_newname(qctx->client, dbuf, &b); - if (name == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - dns_name_copy(signer, name); /* @@ -9723,10 +9686,6 @@ query_synthwildcard(query_ctx_t *qctx, dns_rdataset_t *rdataset, } name = ns_client_newname(qctx->client, dbuf, &b); - if (name == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dns_name_copy(qctx->client->query.qname, name); cloneset = ns_client_newrdataset(qctx->client); @@ -9865,11 +9824,6 @@ query_synthnxdomainnodata(query_ctx_t *qctx, bool nodata, dns_name_t *nowild, } name = ns_client_newname(qctx->client, dbuf, &b); - if (name == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - dns_name_copy(signer, name); /* @@ -9895,11 +9849,6 @@ query_synthnxdomainnodata(query_ctx_t *qctx, bool nodata, dns_name_t *nowild, } name = ns_client_newname(qctx->client, dbuf, &b); - if (name == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - dns_name_copy(nowild, name); cloneset = ns_client_newrdataset(qctx->client); @@ -10534,10 +10483,6 @@ query_dname(query_ctx_t *qctx) { return (ns_query_done(qctx)); } qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, &b); - if (qctx->fname == NULL) { - dns_message_puttempname(qctx->client->message, &tname); - return (ns_query_done(qctx)); - } result = dns_name_concatenate(prefix, tname, qctx->fname, NULL); dns_message_puttempname(qctx->client->message, &tname); @@ -10955,9 +10900,6 @@ db_find: } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); - if (fname == NULL) { - goto cleanup; - } /* * Get the RRSIGs if the client requested them or if we may @@ -11206,9 +11148,6 @@ again: fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); sigrdataset = ns_client_newrdataset(client); - if (fname == NULL) { - goto cleanup; - } result = dns_db_findext(qctx->db, name, qctx->version, dns_rdatatype_nsec, options, 0, &node, fname, @@ -11277,9 +11216,6 @@ again: dns_rdataset_disassociate(sigrdataset); } - if (fname == NULL) { - goto cleanup; - } /* * Add no qname proof. */ @@ -11326,9 +11262,6 @@ again: dns_rdataset_disassociate(sigrdataset); } - if (fname == NULL) { - goto cleanup; - } /* * Add the no wildcard proof. */ From 39fd8efbb77bb38c1cb6504eacd2c79cb9420485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Fri, 10 Jun 2022 14:30:23 +0200 Subject: [PATCH 3/4] Remove NULL checks for ns_client_getnamebuf() ns_client_getnamebuf() cannot fail (i.e. return NULL) since commit e31cc1eeb436095490c7caa120de148df82ecd6c. Remove redundant NULL checks performed on the pointer returned by ns_client_getnamebuf(). --- lib/ns/query.c | 92 ++------------------------------------------------ 1 file changed, 3 insertions(+), 89 deletions(-) diff --git a/lib/ns/query.c b/lib/ns/query.c index 2f72f71b4f..2f0608faaa 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -1711,9 +1711,6 @@ query_additional_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype, * Get some resources. */ dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); if (WANTDNSSEC(client)) { @@ -2441,9 +2438,6 @@ fixfname(ns_client_t *client, dns_name_t **fname, isc_buffer_t **dbuf, isc_buffer_t *nbuf) { if (*fname == NULL) { *dbuf = ns_client_getnamebuf(client); - if (*dbuf == NULL) { - return; - } *fname = ns_client_newname(client, *dbuf, nbuf); } } @@ -5688,13 +5682,6 @@ qctx_prepare_buffers(query_ctx_t *qctx, isc_buffer_t *buffer) { REQUIRE(buffer != NULL); qctx->dbuf = ns_client_getnamebuf(qctx->client); - if (qctx->dbuf == NULL) { - CCTRACE(ISC_LOG_ERROR, - "qctx_prepare_buffers: ns_client_getnamebuf " - "failed"); - return (ISC_R_NOMEMORY); - } - qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, buffer); qctx->rdataset = ns_client_newrdataset(qctx->client); @@ -6628,13 +6615,6 @@ query_resume(query_ctx_t *qctx) { * We'll need some resources... */ qctx->dbuf = ns_client_getnamebuf(qctx->client); - if (qctx->dbuf == NULL) { - CCTRACE(ISC_LOG_ERROR, "query_resume: ns_client_getnamebuf " - "failed (1)"); - QUERY_ERROR(qctx, ISC_R_NOMEMORY); - return (ns_query_done(qctx)); - } - qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, &b); if (qctx->rpz_st != NULL && @@ -7674,10 +7654,6 @@ query_addnoqnameproof(query_ctx_t *qctx) { } dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } - fname = ns_client_newname(client, dbuf, &b); neg = ns_client_newrdataset(client); negsig = ns_client_newrdataset(client); @@ -7694,9 +7670,6 @@ query_addnoqnameproof(query_ctx_t *qctx) { if (fname == NULL) { dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } fname = ns_client_newname(client, dbuf, &b); } @@ -9016,9 +8989,6 @@ addnsec3: * Add the NSEC3 which proves the DS does not exist. */ dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } fname = ns_client_newname(client, dbuf, &b); dns_fixedname_init(&fixed); if (dns_rdataset_isassociated(rdataset)) { @@ -9104,13 +9074,6 @@ query_nodata(query_ctx_t *qctx, isc_result_t res) { RESTORE(qctx->sigrdataset, qctx->client->query.dns64_sigaaaa); if (qctx->fname == NULL) { qctx->dbuf = ns_client_getnamebuf(qctx->client); - if (qctx->dbuf == NULL) { - CCTRACE(ISC_LOG_ERROR, "query_nodata: " - "ns_client_getnamebuf " - "failed (3)"); - QUERY_ERROR(qctx, ISC_R_NOMEMORY); - return (ns_query_done(qctx)); - } qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, &b); } @@ -9362,10 +9325,6 @@ query_addnxrrsetnsec(query_ctx_t *qctx) { * We'll need some resources... */ dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - return; - } - fname = ns_client_newname(client, dbuf, &b); dns_name_split(qctx->fname, sig.labels + 1, NULL, fname); @@ -9599,7 +9558,6 @@ query_synthnodata(query_ctx_t *qctx, const dns_name_t *signer, dns_name_t *name = NULL; dns_ttl_t ttl; isc_buffer_t *dbuf, b; - isc_result_t result; /* * Determine the correct TTL to use for the SOA and RRSIG @@ -9619,11 +9577,6 @@ query_synthnodata(query_ctx_t *qctx, const dns_name_t *signer, } dbuf = ns_client_getnamebuf(qctx->client); - if (dbuf == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - name = ns_client_newname(qctx->client, dbuf, &b); dns_name_copy(signer, name); @@ -9644,14 +9597,12 @@ query_synthnodata(query_ctx_t *qctx, const dns_name_t *signer, &qctx->sigrdataset, NULL, DNS_SECTION_AUTHORITY); } - result = ISC_R_SUCCESS; inc_stats(qctx->client, ns_statscounter_nodatasynth); -cleanup: if (name != NULL) { ns_client_releasename(qctx->client, &name); } - return (result); + return (ISC_R_SUCCESS); } /* @@ -9663,7 +9614,6 @@ query_synthwildcard(query_ctx_t *qctx, dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset) { dns_name_t *name = NULL; isc_buffer_t *dbuf, b; - isc_result_t result; dns_rdataset_t *cloneset = NULL, *clonesigset = NULL; dns_rdataset_t **sigrdatasetp; @@ -9680,11 +9630,6 @@ query_synthwildcard(query_ctx_t *qctx, dns_rdataset_t *rdataset, } dbuf = ns_client_getnamebuf(qctx->client); - if (dbuf == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - name = ns_client_newname(qctx->client, dbuf, &b); dns_name_copy(qctx->client->query.qname, name); @@ -9713,10 +9658,8 @@ query_synthwildcard(query_ctx_t *qctx, dns_rdataset_t *rdataset, &qctx->sigrdataset, NULL, DNS_SECTION_AUTHORITY); } - result = ISC_R_SUCCESS; inc_stats(qctx->client, ns_statscounter_wildcardsynth); -cleanup: if (name != NULL) { ns_client_releasename(qctx->client, &name); } @@ -9726,7 +9669,7 @@ cleanup: if (clonesigset != NULL) { ns_client_putrdataset(qctx->client, &clonesigset); } - return (result); + return (ISC_R_SUCCESS); } /* @@ -9794,7 +9737,6 @@ query_synthnxdomainnodata(query_ctx_t *qctx, bool nodata, dns_name_t *nowild, dns_name_t *name = NULL; dns_ttl_t ttl; isc_buffer_t *dbuf, b; - isc_result_t result; dns_rdataset_t *cloneset = NULL, *clonesigset = NULL; CCTRACE(ISC_LOG_DEBUG(3), "query_synthnxdomain"); @@ -9818,11 +9760,6 @@ query_synthnxdomainnodata(query_ctx_t *qctx, bool nodata, dns_name_t *nowild, } dbuf = ns_client_getnamebuf(qctx->client); - if (dbuf == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - name = ns_client_newname(qctx->client, dbuf, &b); dns_name_copy(signer, name); @@ -9843,11 +9780,6 @@ query_synthnxdomainnodata(query_ctx_t *qctx, bool nodata, dns_name_t *nowild, &qctx->sigrdataset, NULL, DNS_SECTION_AUTHORITY); dbuf = ns_client_getnamebuf(qctx->client); - if (dbuf == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - name = ns_client_newname(qctx->client, dbuf, &b); dns_name_copy(nowild, name); @@ -9870,9 +9802,7 @@ query_synthnxdomainnodata(query_ctx_t *qctx, bool nodata, dns_name_t *nowild, qctx->client->message->rcode = dns_rcode_nxdomain; inc_stats(qctx->client, ns_statscounter_nxdomainsynth); } - result = ISC_R_SUCCESS; -cleanup: if (name != NULL) { ns_client_releasename(qctx->client, &name); } @@ -9882,7 +9812,7 @@ cleanup: if (clonesigset != NULL) { ns_client_putrdataset(qctx->client, &clonesigset); } - return (result); + return (ISC_R_SUCCESS); } /* @@ -10478,10 +10408,6 @@ query_dname(query_ctx_t *qctx) { dns_name_split(qctx->client->query.qname, nlabels, prefix, NULL); INSIST(qctx->fname == NULL); qctx->dbuf = ns_client_getnamebuf(qctx->client); - if (qctx->dbuf == NULL) { - dns_message_puttempname(qctx->client->message, &tname); - return (ns_query_done(qctx)); - } qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, &b); result = dns_name_concatenate(prefix, tname, qctx->fname, NULL); dns_message_puttempname(qctx->client->message, &tname); @@ -10895,9 +10821,6 @@ db_find: * We'll need some resources... */ dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); @@ -11142,9 +11065,6 @@ again: * We'll need some resources... */ dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); sigrdataset = ns_client_newrdataset(client); @@ -11198,9 +11118,6 @@ again: */ if (fname == NULL) { dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } fname = ns_client_newname(client, dbuf, &b); } @@ -11244,9 +11161,6 @@ again: */ if (fname == NULL) { dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) { - goto cleanup; - } fname = ns_client_newname(client, dbuf, &b); } From 07592d1315412c38c978e8d009aace5d0f5bef93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 13 Jun 2022 14:03:16 +0200 Subject: [PATCH 4/4] Check for NULL before dereferencing qctx->rpz_st Commit 9ffb4a7ba11fae64a6ce2dd6390cd334372b7ab7 causes Clang Static Analyzer to flag a potential NULL dereference in query_nxdomain(): query.c:9394:26: warning: Dereference of null pointer [core.NullDereference] if (!qctx->nxrewrite || qctx->rpz_st->m.rpz->addsoa) { ^~~~~~~~~~~~~~~~~~~ 1 warning generated. The warning above is for qctx->rpz_st potentially being a NULL pointer when query_nxdomain() is called from query_resume(). This is a false positive because none of the database lookup result codes currently causing query_nxdomain() to be called (DNS_R_EMPTYWILD, DNS_R_NXDOMAIN) can be returned by a database lookup following a recursive resolution attempt. Add a NULL check nevertheless in order to future-proof the code and silence Clang Static Analyzer. --- lib/ns/query.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ns/query.c b/lib/ns/query.c index 2f0608faaa..18c6a820e1 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -9391,7 +9391,8 @@ query_nxdomain(query_ctx_t *qctx, isc_result_t res) { { ttl = 0; } - if (!qctx->nxrewrite || qctx->rpz_st->m.rpz->addsoa) { + if (!qctx->nxrewrite || + (qctx->rpz_st != NULL && qctx->rpz_st->m.rpz->addsoa)) { result = query_addsoa(qctx, ttl, section); if (result != ISC_R_SUCCESS) { QUERY_ERROR(qctx, result);