Commit 33eefe9f authored by Ondřej Surý's avatar Ondřej Surý

The dns_message_create() cannot fail, change the return to void

The dns_message_create() function cannot soft fail (as all memory
allocations either succeed or cause abort), so we change the function to
return void and cleanup the calls.
parent 7deaf9a9
......@@ -2106,9 +2106,7 @@ setup_lookup(dig_lookup_t *lookup) {
debug("setup_lookup(%p)", lookup);
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
&lookup->sendmsg);
check_result(result, "dns_message_create");
dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &lookup->sendmsg);
if (lookup->new_search) {
debug("resetting lookup counter.");
......@@ -3776,8 +3774,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
goto udp_mismatch;
}
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
check_result(result, "dns_message_create");
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
if (tsigkey != NULL) {
if (l->querysig == NULL) {
......
......@@ -350,16 +350,12 @@ nsu_strsep(char **stringp, const char *delim) {
static void
reset_system(void) {
isc_result_t result;
ddebug("reset_system()");
/* If the update message is still around, destroy it */
if (updatemsg != NULL) {
dns_message_reset(updatemsg, DNS_MESSAGE_INTENTRENDER);
} else {
result = dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER,
&updatemsg);
check_result(result, "dns_message_create");
dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &updatemsg);
}
updatemsg->opcode = dns_opcode_update;
if (usegsstsig) {
......@@ -2413,8 +2409,7 @@ update_completed(isc_task_t *task, isc_event_t *event) {
}
LOCK(&answer_lock);
result = dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &answer);
check_result(result, "dns_message_create");
dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &answer);
result = dns_request_getresponse(request, answer,
DNS_MESSAGEPARSE_PRESERVEORDER);
switch (result) {
......@@ -2606,8 +2601,7 @@ recvsoa(isc_task_t *task, isc_event_t *event) {
reqev = NULL;
ddebug("About to create rcvmsg");
result = dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
check_result(result, "dns_message_create");
dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
result = dns_request_getresponse(request, rcvmsg,
DNS_MESSAGEPARSE_PRESERVEORDER);
if (result == DNS_R_TSIGERRORSET && servers != NULL) {
......@@ -2977,11 +2971,7 @@ start_gssrequest(dns_name_t *master) {
keyname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
rmsg = NULL;
result = dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &rmsg);
if (result != ISC_R_SUCCESS) {
fatal("dns_message_create failed: %s",
isc_result_totext(result));
}
dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &rmsg);
/* Build first request. */
context = GSS_C_NO_CONTEXT;
......@@ -3107,8 +3097,7 @@ recvgss(isc_task_t *task, isc_event_t *event) {
reqev = NULL;
ddebug("recvgss creating rcvmsg");
result = dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
check_result(result, "dns_message_create");
dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
result = dns_request_getresponse(request, rcvmsg,
DNS_MESSAGEPARSE_PRESERVEORDER);
......@@ -3233,8 +3222,7 @@ start_update(void) {
return;
}
result = dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &soaquery);
check_result(result, "dns_message_create");
dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &soaquery);
if (default_servers) {
soaquery->flags |= DNS_MESSAGEFLAG_RD;
......
......@@ -87,8 +87,7 @@ recvresponse(isc_task_t *task, isc_event_t *event) {
query = reqev->ev_arg;
response = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
result = dns_request_getresponse(reqev->request, response,
DNS_MESSAGEPARSE_PRESERVEORDER);
......@@ -152,8 +151,7 @@ sendquery(isc_task_t *task) {
CHECK("dns_name_fromtext", result);
message = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message);
message->opcode = dns_opcode_query;
message->flags |= DNS_MESSAGEFLAG_RD;
......
......@@ -88,8 +88,7 @@ recvquery(isc_task_t *task, isc_event_t *event) {
query = reqev->ev_arg;
response = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
result = dns_request_getresponse(reqev->request, response,
DNS_MESSAGEPARSE_PRESERVEORDER);
......@@ -176,8 +175,7 @@ sendquery(isc_task_t *task, isc_event_t *event) {
CHECK("dns_tsigkey_create", result);
query = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &query);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &query);
result = dns_tkey_builddhquery(query, ourkey,
dns_fixedname_name(&ownername),
......
......@@ -79,8 +79,7 @@ recvquery(isc_task_t *task, isc_event_t *event) {
query = reqev->ev_arg;
response = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
result = dns_request_getresponse(reqev->request, response,
DNS_MESSAGEPARSE_PRESERVEORDER);
......@@ -121,8 +120,7 @@ sendquery(isc_task_t *task, isc_event_t *event) {
isc_sockaddr_fromin(&address, &inaddr, port);
query = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &query);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &query);
result = dns_tkey_builddeletequery(query, tsigkey);
CHECK("dns_tkey_builddeletequery", result);
......
......@@ -277,8 +277,7 @@ process_message(isc_buffer_t *source) {
int i;
message = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
CHECKRESULT(result, "dns_message_create failed");
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
result = dns_message_parse(message, source, parseflags);
if (result == DNS_R_RECOVERABLE) {
......@@ -348,9 +347,7 @@ process_message(isc_buffer_t *source) {
isc_mem_stats(mctx, stdout);
}
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE,
&message);
CHECKRESULT(result, "dns_message_create failed");
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
result = dns_message_parse(message, &buffer, parseflags);
CHECKRESULT(result, "dns_message_parse failed");
......
......@@ -210,8 +210,7 @@ recvresponse(isc_task_t *task, isc_event_t *event) {
}
}
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
parseflags |= DNS_MESSAGEPARSE_PRESERVEORDER;
if (besteffort) {
......@@ -594,8 +593,7 @@ sendquery(struct query *query, isc_task_t *task) {
CHECK("dns_name_fromtext", result);
message = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message);
CHECK("dns_message_create", result);
dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message);
message->opcode = dns_opcode_query;
if (query->recurse) {
......
@@
statement S;
expression V;
@@
- V =
dns_message_create(...);
- if (V != ISC_R_SUCCESS) S
@@
statement S1, S2;
expression V;
@@
- V =
dns_message_create(...);
- if (V == ISC_R_SUCCESS)
S1
- else S2
@@
expression V;
@@
- V =
dns_message_create(...);
- check_result(V, ...);
@@
@@
- CHECK(
dns_message_create(...)
- )
;
@@
@@
- DO(...,
dns_message_create(...)
- )
;
@@
@@
- RETERR(
dns_message_create(...)
- )
;
@@
expression V;
@@
- V =
dns_message_create(...);
- assert_int_equal(V, ISC_R_SUCCESS);
@@
expression V;
@@
- V =
dns_message_create(...);
- CHECK(..., V);
@@
expression V;
statement S;
@@
- V =
dns_message_create(...);
- if (ISC_UNLIKELY(V != ISC_R_SUCCESS)) S
@@
expression V;
@@
- V =
dns_message_create(...);
- RUNTIME_CHECK(V == ISC_R_SUCCESS);
......@@ -47,10 +47,7 @@ parse_message(isc_buffer_t *input, dns_message_t **messagep) {
isc_result_t result;
dns_message_t *message = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
result = dns_message_parse(message, input, DNS_MESSAGEPARSE_BESTEFFORT);
if (result == DNS_R_RECOVERABLE) {
......
......@@ -1936,11 +1936,7 @@ update_done(isc_task_t *task, isc_event_t *event) {
goto out;
}
result = dns_message_create(client->mctx, DNS_MESSAGE_INTENTPARSE,
&answer);
if (result != ISC_R_SUCCESS) {
goto out;
}
dns_message_create(client->mctx, DNS_MESSAGE_INTENTPARSE, &answer);
uctx->state = dns_clientupdatestate_done;
result = dns_request_getresponse(request, answer,
DNS_MESSAGEPARSE_PRESERVEORDER);
......@@ -2270,11 +2266,8 @@ receive_soa(isc_task_t *task, isc_event_t *event) {
goto out;
}
result = dns_message_create(uctx->client->mctx, DNS_MESSAGE_INTENTPARSE,
&rcvmsg);
if (result != ISC_R_SUCCESS) {
goto out;
}
dns_message_create(uctx->client->mctx, DNS_MESSAGE_INTENTPARSE,
&rcvmsg);
result = dns_request_getresponse(request, rcvmsg,
DNS_MESSAGEPARSE_PRESERVEORDER);
......@@ -2421,12 +2414,8 @@ request_soa(updatectx_t *uctx) {
unsigned int reqoptions;
if (soaquery == NULL) {
result = dns_message_create(uctx->client->mctx,
DNS_MESSAGE_INTENTRENDER,
&soaquery);
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_message_create(uctx->client->mctx, DNS_MESSAGE_INTENTRENDER,
&soaquery);
}
soaquery->flags |= DNS_MESSAGEFLAG_RD;
result = dns_message_gettempname(soaquery, &name);
......@@ -2878,11 +2867,8 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass,
}
/* Make update message */
result = dns_message_create(client->mctx, DNS_MESSAGE_INTENTRENDER,
&uctx->updatemsg);
if (result != ISC_R_SUCCESS) {
goto fail;
}
dns_message_create(client->mctx, DNS_MESSAGE_INTENTRENDER,
&uctx->updatemsg);
uctx->updatemsg->opcode = dns_opcode_update;
if (prerequisites != NULL) {
......
......@@ -1143,7 +1143,7 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) {
isc_buffer_init(&b, d->msgdata.base, d->msgdata.length);
isc_buffer_add(&b, d->msgdata.length);
CHECK(dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &d->msg));
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &d->msg);
result = dns_message_parse(d->msg, &b, 0);
if (result != ISC_R_SUCCESS) {
if (result != DNS_R_RECOVERABLE) {
......
......@@ -9,8 +9,7 @@
* information regarding copyright ownership.
*/
#ifndef DNS_MESSAGE_H
#define DNS_MESSAGE_H 1
#pragma once
/***
*** Imports
......@@ -203,8 +202,8 @@ struct dns_sortlist_arg {
struct dns_message {
/* public from here down */
unsigned int magic;
isc_refcount_t refcount;
unsigned int magic;
isc_refcount_t refcount;
dns_messageid_t id;
unsigned int flags;
......@@ -295,7 +294,7 @@ struct dns_ednsopt {
ISC_LANG_BEGINDECLS
isc_result_t
void
dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp);
/*%<
......@@ -1506,5 +1505,3 @@ dns_message_clonebuffer(dns_message_t *msg);
*/
ISC_LANG_ENDDECLS
#endif /* DNS_MESSAGE_H */
......@@ -714,7 +714,7 @@ spacefortsig(dns_tsigkey_t *key, int otherlen) {
return (26 + r1.length + r2.length + x + otherlen);
}
isc_result_t
void
dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) {
dns_message_t *m;
isc_buffer_t *dynbuf;
......@@ -728,11 +728,6 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) {
m = isc_mem_get(mctx, sizeof(dns_message_t));
/*
* No allocations until further notice. Just initialize all lists
* and other members that are freed in the cleanup phase here.
*/
m->magic = DNS_MESSAGE_MAGIC;
m->from_to_wire = intent;
msginit(m);
......@@ -754,10 +749,6 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) {
ISC_LIST_INIT(m->freerdata);
ISC_LIST_INIT(m->freerdatalist);
/*
* Ok, it is safe to allocate (and then "goto cleanup" if failure)
*/
isc_mempool_create(m->mctx, sizeof(dns_name_t), &m->namepool);
isc_mempool_setfillcount(m->namepool, NAME_COUNT);
isc_mempool_setfreemax(m->namepool, NAME_COUNT);
......@@ -777,7 +768,6 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) {
isc_refcount_init(&m->refcount, 1);
*msgp = m;
return (ISC_R_SUCCESS);
}
void
......
......@@ -2020,8 +2020,8 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
query = isc_mem_get(fctx->mctx, sizeof(*query));
query->rmessage = NULL;
result = dns_message_create(fctx->mctx, DNS_MESSAGE_INTENTPARSE,
&query->rmessage);
dns_message_create(fctx->mctx, DNS_MESSAGE_INTENTPARSE,
&query->rmessage);
query->mctx = fctx->mctx;
query->options = options;
query->attributes = 0;
......@@ -5130,12 +5130,7 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type,
}
fctx->qmessage = NULL;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
&fctx->qmessage);
if (result != ISC_R_SUCCESS) {
goto cleanup_fcount;
}
dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &fctx->qmessage);
/*
* Compute an expiration time for the entire fetch.
......
......@@ -209,8 +209,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
dns_compress_t cctx;
isc_result_t result;
result = dns_message_create(dt_mctx, DNS_MESSAGE_INTENTRENDER, &msg);
assert_int_equal(result, ISC_R_SUCCESS);
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTRENDER, &msg);
assert_non_null(msg);
msg->id = 50;
......@@ -322,8 +321,7 @@ tsig_tcp_test(void **state) {
/*
* Process response message 1.
*/
result = dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_int_equal(result, ISC_R_SUCCESS);
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_non_null(msg);
result = dns_message_settsigkey(msg, key);
......@@ -377,8 +375,7 @@ tsig_tcp_test(void **state) {
/*
* Process response message 2.
*/
result = dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_int_equal(result, ISC_R_SUCCESS);
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_non_null(msg);
msg->tcp_continuation = 1;
......@@ -424,8 +421,7 @@ tsig_tcp_test(void **state) {
/*
* Process response message 3.
*/
result = dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_int_equal(result, ISC_R_SUCCESS);
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_non_null(msg);
msg->tcp_continuation = 1;
......
......@@ -1104,7 +1104,7 @@ xfrin_send_request(dns_xfrin_ctx_t *xfr) {
dns_name_t *msgsoaname = NULL;
/* Create the request message */
CHECK(dns_message_create(xfr->mctx, DNS_MESSAGE_INTENTRENDER, &msg));
dns_message_create(xfr->mctx, DNS_MESSAGE_INTENTRENDER, &msg);
CHECK(dns_message_settsigkey(msg, xfr->tsigkey));
/* Create a name for the question section. */
......@@ -1254,7 +1254,7 @@ xfrin_recv_done(isc_task_t *task, isc_event_t *ev) {
CHECK(isc_timer_touch(xfr->timer));
CHECK(dns_message_create(xfr->mctx, DNS_MESSAGE_INTENTPARSE, &msg));
dns_message_create(xfr->mctx, DNS_MESSAGE_INTENTPARSE, &msg);
CHECK(dns_message_settsigkey(msg, xfr->tsigkey));
CHECK(dns_message_setquerytsig(msg, xfr->lasttsig));
......
......@@ -12639,10 +12639,7 @@ stub_callback(isc_task_t *task, isc_event_t *event) {
goto next_master;
}
result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg);
if (result != ISC_R_SUCCESS) {
goto next_master;
}
dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg);
result = dns_request_getresponse(revent->request, msg, 0);
if (result != ISC_R_SUCCESS) {
......@@ -13044,10 +13041,7 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
goto next_master;
}
result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg);
if (result != ISC_R_SUCCESS) {
goto next_master;
}
dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg);
result = dns_request_getresponse(revent->request, msg, 0);
if (result != ISC_R_SUCCESS) {
dns_zone_log(zone, ISC_LOG_INFO,
......@@ -13430,11 +13424,7 @@ create_query(dns_zone_t *zone, dns_rdatatype_t rdtype,
dns_rdataset_t *qrdataset = NULL;
isc_result_t result;
result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTRENDER,
&message);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
dns_message_create(zone->mctx, DNS_MESSAGE_INTENTRENDER, &message);
message->opcode = dns_opcode_query;
message->rdclass = zone->rdclass;
......@@ -14313,11 +14303,7 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags,
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(messagep != NULL && *messagep == NULL);
result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTRENDER,
&message);
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_message_create(zone->mctx, DNS_MESSAGE_INTENTRENDER, &message);
message->opcode = dns_opcode_notify;
message->flags |= DNS_MESSAGEFLAG_AA;
......@@ -15245,12 +15231,10 @@ notify_done(isc_task_t *task, isc_event_t *event) {
isc_buffer_init(&buf, rcode, sizeof(rcode));
isc_sockaddr_format(&notify->dst, addrbuf, sizeof(addrbuf));
dns_message_create(notify->zone->mctx, DNS_MESSAGE_INTENTPARSE,
&message);
result = revent->result;
if (result == ISC_R_SUCCESS) {
result = dns_message_create(notify->zone->mctx,
DNS_MESSAGE_INTENTPARSE, &message);
}
if (result == ISC_R_SUCCESS) {
result =
dns_request_getresponse(revent->request, message,
......@@ -15274,7 +15258,7 @@ notify_done(isc_task_t *task, isc_event_t *event) {
* the soa if we see a formerr and had sent a SOA.
*/
isc_event_free(&event);
if (message != NULL && message->rcode == dns_rcode_formerr &&
if (message->rcode == dns_rcode_formerr &&
(notify->flags & DNS_NOTIFY_NOSOA) == 0)
{
bool startup;
......@@ -15293,9 +15277,7 @@ notify_done(isc_task_t *task, isc_event_t *event) {
}
notify_destroy(notify, false);
}
if (message != NULL) {
dns_message_detach(&message);
}
dns_message_detach(&message);
}
struct secure_event {
......@@ -17259,10 +17241,7 @@ forward_callback(isc_task_t *task, isc_event_t *event) {
goto next_master;
}
result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg);
if (result != ISC_R_SUCCESS) {
goto next_master;
}
dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg);
result = dns_request_getresponse(revent->request, msg,
DNS_MESSAGEPARSE_PRESERVEORDER |
......
......@@ -2277,12 +2277,8 @@ ns__client_setup(ns_client_t *client, ns_clientmgr_t *mgr, bool new) {
ns_server_attach(mgr->sctx, &client->sctx);
get_clienttask(mgr, &client->task);
result = dns_message_create(client->mctx,
DNS_MESSAGE_INTENTPARSE,
&client->message);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
dns_message_create(client->mctx, DNS_MESSAGE_INTENTPARSE,
&client->message);
client->sendbuf = isc_mem_get(client->mctx,
NS_CLIENT_SEND_BUFFER_SIZE);
......
......@@ -66,8 +66,7 @@ check_response(isc_buffer_t *buf) {
char rcodebuf[20];
isc_buffer_t b;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
assert_int_equal(result, ISC_R_SUCCESS);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);