2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Cleanup dns_message_gettemp*() functions - they cannot fail

The dns_message_gettempname(), dns_message_gettemprdata(),
dns_message_gettemprdataset(), and dns_message_gettemprdatalist() always
succeeds because the memory allocation cannot fail now.  Change the API
to return void and cleanup all the use of aforementioned functions.
This commit is contained in:
Ondřej Surý
2022-05-16 13:28:13 +02:00
parent edbb52c95c
commit 33ba0057a7
18 changed files with 277 additions and 431 deletions

View File

@@ -2778,15 +2778,11 @@ ns_client_sourceip(dns_clientinfo_t *ci, isc_sockaddr_t **addrp) {
dns_rdataset_t *
ns_client_newrdataset(ns_client_t *client) {
dns_rdataset_t *rdataset;
isc_result_t result;
REQUIRE(NS_CLIENT_VALID(client));
rdataset = NULL;
result = dns_message_gettemprdataset(client->message, &rdataset);
if (result != ISC_R_SUCCESS) {
return (NULL);
}
dns_message_gettemprdataset(client->message, &rdataset);
return (rdataset);
}
@@ -2825,18 +2821,12 @@ dns_name_t *
ns_client_newname(ns_client_t *client, isc_buffer_t *dbuf, isc_buffer_t *nbuf) {
dns_name_t *name = NULL;
isc_region_t r;
isc_result_t result;
REQUIRE((client->query.attributes & NS_QUERYATTR_NAMEBUFUSED) == 0);
CTRACE("ns_client_newname");
result = dns_message_gettempname(client->message, &name);
if (result != ISC_R_SUCCESS) {
CTRACE("ns_client_newname: "
"dns_message_gettempname failed: done");
return (NULL);
}
dns_message_gettempname(client->message, &name);
isc_buffer_availableregion(dbuf, &r);
isc_buffer_init(nbuf, r.base, r.length);
dns_name_setbuffer(name, NULL);

View File

@@ -8352,15 +8352,8 @@ query_dns64(query_ctx_t *qctx) {
isc_buffer_allocate(client->manager->mctx, &buffer,
view->dns64cnt * 16 *
dns_rdataset_count(qctx->rdataset));
result = dns_message_gettemprdataset(client->message, &dns64_rdataset);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
result = dns_message_gettemprdatalist(client->message,
&dns64_rdatalist);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
dns_message_gettemprdataset(client->message, &dns64_rdataset);
dns_message_gettemprdatalist(client->message, &dns64_rdatalist);
dns_rdatalist_init(dns64_rdatalist);
dns64_rdatalist->rdclass = dns_rdataclass_in;
@@ -8406,11 +8399,7 @@ query_dns64(query_ctx_t *qctx) {
isc_buffer_add(buffer, 16);
isc_buffer_remainingregion(buffer, &r);
isc_buffer_forward(buffer, 16);
result = dns_message_gettemprdata(client->message,
&dns64_rdata);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
dns_message_gettemprdata(client->message, &dns64_rdata);
dns_rdata_init(dns64_rdata);
dns_rdata_fromregion(dns64_rdata, dns_rdataclass_in,
dns_rdatatype_aaaa, &r);
@@ -8531,14 +8520,8 @@ query_filter64(query_ctx_t *qctx) {
isc_buffer_allocate(client->manager->mctx, &buffer,
16 * dns_rdataset_count(qctx->rdataset));
result = dns_message_gettemprdataset(client->message, &myrdataset);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
result = dns_message_gettemprdatalist(client->message, &myrdatalist);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
dns_message_gettemprdataset(client->message, &myrdataset);
dns_message_gettemprdatalist(client->message, &myrdatalist);
dns_rdatalist_init(myrdatalist);
myrdatalist->rdclass = dns_rdataclass_in;
@@ -8558,10 +8541,7 @@ query_filter64(query_ctx_t *qctx) {
isc_buffer_putmem(buffer, rdata.data, rdata.length);
isc_buffer_remainingregion(buffer, &r);
isc_buffer_forward(buffer, rdata.length);
result = dns_message_gettemprdata(client->message, &myrdata);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
dns_message_gettemprdata(client->message, &myrdata);
dns_rdata_init(myrdata);
dns_rdata_fromregion(myrdata, dns_rdataclass_in,
dns_rdatatype_aaaa, &r);
@@ -9885,10 +9865,7 @@ query_synthcnamewildcard(query_ctx_t *qctx, dns_rdataset_t *rdataset,
* Reset qname to be the target name of the CNAME and restart
* the query.
*/
result = dns_message_gettempname(qctx->client->message, &tname);
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_message_gettempname(qctx->client->message, &tname);
result = dns_rdataset_first(rdataset);
if (result != ISC_R_SUCCESS) {
@@ -10510,10 +10487,7 @@ query_cname(query_ctx_t *qctx) {
* Reset qname to be the target name of the CNAME and restart
* the query.
*/
result = dns_message_gettempname(qctx->client->message, &tname);
if (result != ISC_R_SUCCESS) {
return (ns_query_done(qctx));
}
dns_message_gettempname(qctx->client->message, &tname);
result = dns_rdataset_first(trdataset);
if (result != ISC_R_SUCCESS) {
@@ -10612,10 +10586,7 @@ query_dname(query_ctx_t *qctx) {
* Get the target name of the DNAME.
*/
tname = NULL;
result = dns_message_gettempname(qctx->client->message, &tname);
if (result != ISC_R_SUCCESS) {
return (ns_query_done(qctx));
}
dns_message_gettempname(qctx->client->message, &tname);
result = dns_rdataset_first(trdataset);
if (result != ISC_R_SUCCESS) {
@@ -10720,35 +10691,16 @@ query_addcname(query_ctx_t *qctx, dns_trust_t trust, dns_ttl_t ttl) {
dns_rdata_t *rdata = NULL;
isc_region_t r;
dns_name_t *aname = NULL;
isc_result_t result;
result = dns_message_gettempname(client->message, &aname);
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_message_gettempname(client->message, &aname);
dns_name_copy(client->query.qname, aname);
result = dns_message_gettemprdatalist(client->message, &rdatalist);
if (result != ISC_R_SUCCESS) {
dns_message_puttempname(client->message, &aname);
return (result);
}
dns_message_gettemprdatalist(client->message, &rdatalist);
result = dns_message_gettemprdata(client->message, &rdata);
if (result != ISC_R_SUCCESS) {
dns_message_puttempname(client->message, &aname);
dns_message_puttemprdatalist(client->message, &rdatalist);
return (result);
}
dns_message_gettemprdata(client->message, &rdata);
result = dns_message_gettemprdataset(client->message, &rdataset);
if (result != ISC_R_SUCCESS) {
dns_message_puttempname(client->message, &aname);
dns_message_puttemprdatalist(client->message, &rdatalist);
dns_message_puttemprdata(client->message, &rdata);
return (result);
}
dns_message_gettemprdataset(client->message, &rdataset);
rdatalist->type = dns_rdatatype_cname;
rdatalist->rdclass = client->message->rdclass;
@@ -10858,10 +10810,7 @@ query_addsoa(query_ctx_t *qctx, unsigned int override_ttl,
/*
* Get resources and make 'name' be the database origin.
*/
result = dns_message_gettempname(client->message, &name);
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_message_gettempname(client->message, &name);
/*
* We'll be releasing 'name' before returning, so it's safe to
@@ -10998,12 +10947,7 @@ query_addns(query_ctx_t *qctx) {
/*
* Get resources and make 'name' be the database origin.
*/
result = dns_message_gettempname(client->message, &name);
if (result != ISC_R_SUCCESS) {
CTRACE(ISC_LOG_DEBUG(3), "query_addns: dns_message_gettempname "
"failed: done");
return (result);
}
dns_message_gettempname(client->message, &name);
dns_name_clone(dns_db_origin(qctx->db), name);
rdataset = ns_client_newrdataset(client);
if (rdataset == NULL) {

View File

@@ -614,14 +614,8 @@ attach_query_msg_to_client(ns_client_t *client, const char *qnamestr,
/*
* Allocate structures required to construct the query.
*/
result = dns_message_gettemprdataset(message, &qrdataset);
if (result != ISC_R_SUCCESS) {
goto destroy_message;
}
result = dns_message_gettempname(message, &qname);
if (result != ISC_R_SUCCESS) {
goto put_rdataset;
}
dns_message_gettemprdataset(message, &qrdataset);
dns_message_gettempname(message, &qname);
/*
* Convert "qnamestr" to a DNS name, create a question rdataset of
@@ -669,7 +663,6 @@ attach_query_msg_to_client(ns_client_t *client, const char *qnamestr,
put_name:
dns_message_puttempname(message, &qname);
put_rdataset:
dns_message_puttemprdataset(message, &qrdataset);
destroy_message:
dns_message_detach(&message);

View File

@@ -1386,18 +1386,12 @@ sendstream(xfrout_ctx_t *xfr) {
isc_buffer_add(&xfr->buf, 12 + 4);
qrdataset = NULL;
result = dns_message_gettemprdataset(msg, &qrdataset);
if (result != ISC_R_SUCCESS) {
goto failure;
}
dns_message_gettemprdataset(msg, &qrdataset);
dns_rdataset_makequestion(qrdataset,
xfr->client->message->rdclass,
xfr->qtype);
result = dns_message_gettempname(msg, &qname);
if (result != ISC_R_SUCCESS) {
goto failure;
}
dns_message_gettempname(msg, &qname);
isc_buffer_availableregion(&xfr->buf, &r);
INSIST(r.length >= xfr->qname->length);
r.length = xfr->qname->length;
@@ -1467,10 +1461,7 @@ sendstream(xfrout_ctx_t *xfr) {
log_rr(name, rdata, ttl); /* XXX */
}
result = dns_message_gettempname(msg, &msgname);
if (result != ISC_R_SUCCESS) {
goto failure;
}
dns_message_gettempname(msg, &msgname);
isc_buffer_availableregion(&xfr->buf, &r);
INSIST(r.length >= name->length);
r.length = name->length;
@@ -1480,20 +1471,14 @@ sendstream(xfrout_ctx_t *xfr) {
/* Reserve space for RR header. */
isc_buffer_add(&xfr->buf, 10);
result = dns_message_gettemprdata(msg, &msgrdata);
if (result != ISC_R_SUCCESS) {
goto failure;
}
dns_message_gettemprdata(msg, &msgrdata);
isc_buffer_availableregion(&xfr->buf, &r);
r.length = rdata->length;
isc_buffer_putmem(&xfr->buf, rdata->data, rdata->length);
dns_rdata_init(msgrdata);
dns_rdata_fromregion(msgrdata, rdata->rdclass, rdata->type, &r);
result = dns_message_gettemprdatalist(msg, &msgrdl);
if (result != ISC_R_SUCCESS) {
goto failure;
}
dns_message_gettemprdatalist(msg, &msgrdl);
msgrdl->type = rdata->type;
msgrdl->rdclass = rdata->rdclass;
msgrdl->ttl = ttl;
@@ -1505,10 +1490,7 @@ sendstream(xfrout_ctx_t *xfr) {
}
ISC_LIST_APPEND(msgrdl->rdata, msgrdata, link);
result = dns_message_gettemprdataset(msg, &msgrds);
if (result != ISC_R_SUCCESS) {
goto failure;
}
dns_message_gettemprdataset(msg, &msgrds);
result = dns_rdatalist_tordataset(msgrdl, msgrds);
INSIST(result == ISC_R_SUCCESS);