From 33eefe9f8565592c31d1ab086107c83733530f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 25 Sep 2020 11:51:36 +0200 Subject: [PATCH] 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. --- bin/dig/dighost.c | 7 +- bin/nsupdate/nsupdate.c | 24 ++----- bin/tests/system/pipelined/pipequeries.c | 6 +- bin/tests/system/tkey/keycreate.c | 6 +- bin/tests/system/tkey/keydelete.c | 6 +- bin/tests/wire_test.c | 7 +- bin/tools/mdig.c | 6 +- cocci/dns_message_create.spatch | 84 ++++++++++++++++++++++++ fuzz/dns_message_parse.c | 5 +- lib/dns/client.c | 28 ++------ lib/dns/dnstap.c | 2 +- lib/dns/include/dns/message.h | 11 ++-- lib/dns/message.c | 12 +--- lib/dns/resolver.c | 11 +--- lib/dns/tests/tsig_test.c | 12 ++-- lib/dns/xfrin.c | 4 +- lib/dns/zone.c | 39 +++-------- lib/ns/client.c | 8 +-- lib/ns/tests/notify_test.c | 6 +- lib/ns/tests/nstest.c | 5 +- lib/ns/xfrout.c | 4 +- lib/samples/nsprobe.c | 15 ++--- lib/samples/sample-request.c | 11 +--- 23 files changed, 147 insertions(+), 172 deletions(-) create mode 100644 cocci/dns_message_create.spatch diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index b1ed60c58a..1393ac7d88 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -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) { diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index b3fed5d500..2d10feb95d 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -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; diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index 7bafdc66b0..38335a148e 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -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; diff --git a/bin/tests/system/tkey/keycreate.c b/bin/tests/system/tkey/keycreate.c index 8fa5a7d2f1..e2ecc74761 100644 --- a/bin/tests/system/tkey/keycreate.c +++ b/bin/tests/system/tkey/keycreate.c @@ -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), diff --git a/bin/tests/system/tkey/keydelete.c b/bin/tests/system/tkey/keydelete.c index 15fb84b2f0..2fb173bd39 100644 --- a/bin/tests/system/tkey/keydelete.c +++ b/bin/tests/system/tkey/keydelete.c @@ -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); diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index f420d8992c..107f2cc7a1 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -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"); diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index 0f7ddcdffb..c6e4ea4316 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -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) { diff --git a/cocci/dns_message_create.spatch b/cocci/dns_message_create.spatch new file mode 100644 index 0000000000..bab6d587f6 --- /dev/null +++ b/cocci/dns_message_create.spatch @@ -0,0 +1,84 @@ +@@ +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); diff --git a/fuzz/dns_message_parse.c b/fuzz/dns_message_parse.c index 0f80465b43..1b7f24573a 100644 --- a/fuzz/dns_message_parse.c +++ b/fuzz/dns_message_parse.c @@ -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) { diff --git a/lib/dns/client.c b/lib/dns/client.c index 2f18855188..c1a9b95d87 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -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) { diff --git a/lib/dns/dnstap.c b/lib/dns/dnstap.c index 064f1b2586..44fb25e73c 100644 --- a/lib/dns/dnstap.c +++ b/lib/dns/dnstap.c @@ -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) { diff --git a/lib/dns/include/dns/message.h b/lib/dns/include/dns/message.h index 1f13bcf2fd..f1927863bf 100644 --- a/lib/dns/include/dns/message.h +++ b/lib/dns/include/dns/message.h @@ -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 */ diff --git a/lib/dns/message.c b/lib/dns/message.c index b8fd4dee93..03b723045f 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -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 diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index a5f95e7f16..f7e4d0d1a7 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -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. diff --git a/lib/dns/tests/tsig_test.c b/lib/dns/tests/tsig_test.c index 85821b1258..e5bae9864b 100644 --- a/lib/dns/tests/tsig_test.c +++ b/lib/dns/tests/tsig_test.c @@ -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; diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index d24816af28..952d16a481 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -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)); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 267735ee5d..1faa26d853 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -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(¬ify->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 | diff --git a/lib/ns/client.c b/lib/ns/client.c index 021d19eec1..a2eed9250d 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -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); diff --git a/lib/ns/tests/notify_test.c b/lib/ns/tests/notify_test.c index ce97dd9fdc..b013dc209c 100644 --- a/lib/ns/tests/notify_test.c +++ b/lib/ns/tests/notify_test.c @@ -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); result = dns_message_parse(message, buf, 0); assert_int_equal(result, ISC_R_SUCCESS); @@ -115,8 +114,7 @@ notify_start(void **state) { isc_buffer_init(&nbuf, ndata, nsize); isc_buffer_add(&nbuf, nsize); - result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &nmsg); - assert_int_equal(result, ISC_R_SUCCESS); + dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &nmsg); result = dns_message_parse(nmsg, &nbuf, 0); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/ns/tests/nstest.c b/lib/ns/tests/nstest.c index 17989147b3..039e158a78 100644 --- a/lib/ns/tests/nstest.c +++ b/lib/ns/tests/nstest.c @@ -614,10 +614,7 @@ attach_query_msg_to_client(ns_client_t *client, const char *qnamestr, /* * Create a new DNS message holding a query. */ - result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message); - if (result != ISC_R_SUCCESS) { - return (result); - } + dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message); /* * Set query ID to a random value. diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index 3118e70942..9eb283ff00 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -1334,8 +1334,8 @@ sendstream(xfrout_ctx_t *xfr) { * message. */ - CHECK(dns_message_create(xfr->mctx, DNS_MESSAGE_INTENTRENDER, - &tcpmsg)); + dns_message_create(xfr->mctx, DNS_MESSAGE_INTENTRENDER, + &tcpmsg); msg = tcpmsg; msg->id = xfr->id; diff --git a/lib/samples/nsprobe.c b/lib/samples/nsprobe.c index 141d481bc0..eb626086f0 100644 --- a/lib/samples/nsprobe.c +++ b/lib/samples/nsprobe.c @@ -1170,17 +1170,10 @@ main(int argc, char *argv[]) { probes[i].reqid = NULL; probes[i].qmessage = NULL; - result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, - &probes[i].qmessage); - if (result == ISC_R_SUCCESS) { - result = dns_message_create(mctx, - DNS_MESSAGE_INTENTPARSE, - &probes[i].rmessage); - } - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "initialization failure\n"); - exit(1); - } + dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, + &probes[i].qmessage); + dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, + &probes[i].rmessage); } for (i = 0; i < MAX_PROBES; i++) { result = probe_domain(&probes[i]); diff --git a/lib/samples/sample-request.c b/lib/samples/sample-request.c index af5ec1e2d9..00ff2d58d3 100644 --- a/lib/samples/sample-request.c +++ b/lib/samples/sample-request.c @@ -191,15 +191,8 @@ main(int argc, char *argv[]) { rmessage = NULL; isc_mem_create(&mctx); - result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &qmessage); - if (result == ISC_R_SUCCESS) { - result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, - &rmessage); - } - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to create messages\n"); - exit(1); - } + dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &qmessage); + dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &rmessage); /* Initialize the nameserver address */ memset(&hints, 0, sizeof(hints));