Refactor the isc_buffer_allocate() usage using the semantic patch

The isc_buffer_allocate() function now cannot fail with ISC_R_MEMORY.
This commit removes all the checks on the return code using the semantic
patch from previous commit, as isc_buffer_allocate() now returns void.
This commit is contained in:
Ondřej Surý 2020-02-02 08:35:46 +01:00
parent d5f682a00b
commit c73e5866c4
41 changed files with 97 additions and 278 deletions

View file

@ -568,8 +568,7 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf,
if (!query->lookup->comments)
flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
result = isc_buffer_allocate(mctx, &buf, len);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &buf, len);
if (yaml) {
enum { Q = 0x1, R = 0x2 }; /* Q:query; R:ecursive */
@ -742,11 +741,8 @@ repopulate_buffer:
buftoosmall:
len += OUTPUTBUF;
isc_buffer_free(&buf);
result = isc_buffer_allocate(mctx, &buf, len);
if (result == ISC_R_SUCCESS)
goto repopulate_buffer;
else
goto cleanup;
isc_buffer_allocate(mctx, &buf, len);
goto repopulate_buffer;
}
check_result(result,
"dns_message_pseudosectiontotext");
@ -827,7 +823,6 @@ buftoosmall:
(char *)isc_buffer_base(buf));
isc_buffer_free(&buf);
cleanup:
if (style != NULL)
dns_master_styledestroy(&style, mctx);
return (result);

View file

@ -883,10 +883,8 @@ setup_text_key(void) {
unsigned char *secretstore;
debug("setup_text_key()");
result = isc_buffer_allocate(mctx, &namebuf, MXNAME);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &namebuf, MXNAME);
dns_name_init(&keyname, NULL);
check_result(result, "dns_name_init");
isc_buffer_putstr(namebuf, keynametext);
secretsize = (unsigned int) strlen(keysecret) * 3 / 4;
secretstore = isc_mem_allocate(mctx, secretsize);

View file

@ -199,8 +199,7 @@ say_message(dns_name_t *name, const char *msg, dns_rdata_t *rdata,
dns_name_format(name, namestr, sizeof(namestr));
retry:
result = isc_buffer_allocate(mctx, &b, bufsize);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &b, bufsize);
result = dns_rdata_totext(rdata, NULL, b);
if (result == ISC_R_NOSPACE) {
isc_buffer_free(&b);

View file

@ -221,9 +221,7 @@ printrdata(dns_rdata_t *rdata) {
printf("rdata_%d = ", rdata->type);
while (!done) {
result = isc_buffer_allocate(mctx, &b, size);
if (result != ISC_R_SUCCESS)
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &b, size);
result = dns_rdata_totext(rdata, NULL, b);
if (result == ISC_R_SUCCESS) {
printf("%.*s\n", (int)isc_buffer_usedlength(b),

View file

@ -370,8 +370,7 @@ formatset(dns_rdataset_t *rdataset) {
mctx);
check_result(result, "dns_master_stylecreate2 failed");
result = isc_buffer_allocate(mctx, &buf, MAX_CDS_RDATA_TEXT_SIZE);
check_result(result, "printing DS records");
isc_buffer_allocate(mctx, &buf, MAX_CDS_RDATA_TEXT_SIZE);
result = dns_master_rdatasettotext(name, rdataset, style, NULL, buf);
if ((result == ISC_R_SUCCESS) && isc_buffer_availablelength(buf) < 1) {
@ -834,8 +833,7 @@ make_new_ds_set(ds_maker_func_t *ds_from_rdata,
result = dns_rdatalist_tordataset(dslist, &new_ds_set);
check_result(result, "dns_rdatalist_tordataset(dslist)");
result = isc_buffer_allocate(mctx, &new_ds_buf, size);
check_result(result, "building new DS records");
isc_buffer_allocate(mctx, &new_ds_buf, size);
for (result = dns_rdataset_first(rdset);
result == ISC_R_SUCCESS;

View file

@ -226,8 +226,7 @@ dumpnode(dns_name_t *name, dns_dbnode_t *node) {
dns_rdataset_init(&rds);
result = isc_buffer_allocate(mctx, &buffer, bufsize);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &buffer, bufsize);
for (result = dns_rdatasetiter_first(iter);
result == ISC_R_SUCCESS;
@ -253,8 +252,7 @@ dumpnode(dns_name_t *name, dns_dbnode_t *node) {
bufsize <<= 1;
isc_buffer_free(&buffer);
result = isc_buffer_allocate(mctx, &buffer, bufsize);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &buffer, bufsize);
}
check_result(result, "dns_master_rdatasettotext");

View file

@ -445,9 +445,7 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) {
goto cleanup_request;
}
result = isc_buffer_allocate(listener->mctx, &text, 2 * 2048);
if (result != ISC_R_SUCCESS)
goto cleanup_request;
isc_buffer_allocate(listener->mctx, &text, 2 * 2048);
/*
* Establish nonce.
@ -493,10 +491,7 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) {
goto cleanup_response;
if (conn->buffer == NULL) {
result = isc_buffer_allocate(listener->mctx,
&conn->buffer, 2 * 2048);
if (result != ISC_R_SUCCESS)
goto cleanup_response;
isc_buffer_allocate(listener->mctx, &conn->buffer, 2 * 2048);
}
isc_buffer_clear(conn->buffer);

View file

@ -7694,9 +7694,7 @@ data_to_cfg(dns_view_t *view, MDB_val *key, MDB_val *data,
REQUIRE(zoneconfig != NULL && *zoneconfig == NULL);
if (*text == NULL) {
result = isc_buffer_allocate(view->mctx, text, 256);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(view->mctx, text, 256);
} else {
isc_buffer_clear(*text);
}
@ -12394,17 +12392,7 @@ nzd_save(MDB_txn **txnp, MDB_dbi dbi, dns_zone_t *zone,
/* We're creating or overwriting the zone */
const cfg_obj_t *zoptions;
result = isc_buffer_allocate(view->mctx, &text, 256);
if (result != ISC_R_SUCCESS) {
isc_log_write(named_g_lctx,
NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER,
ISC_LOG_ERROR,
"Unable to allocate buffer in "
"nzd_save(): %s",
isc_result_totext(result));
goto cleanup;
}
isc_buffer_allocate(view->mctx, &text, 256);
zoptions = cfg_tuple_get(zconfig, "options");
if (zoptions == NULL) {
@ -12429,7 +12417,7 @@ nzd_save(MDB_txn **txnp, MDB_dbi dbi, dns_zone_t *zone,
ISC_LOG_ERROR,
"Error writing zone config to "
"buffer in nzd_save(): %s",
isc_result_totext(result));
isc_result_totext(dzarg.result));
result = dzarg.result;
goto cleanup;
}
@ -12761,7 +12749,7 @@ migrate_nzf(dns_view_t *view) {
CHECK(nzd_open(view, 0, &txn, &dbi));
CHECK(isc_buffer_allocate(view->mctx, &text, 256));
isc_buffer_allocate(view->mctx, &text, 256);
for (element = cfg_list_first(zonelist);
element != NULL;

View file

@ -1238,8 +1238,7 @@ parse_name(char **cmdlinep, dns_message_t *msg, dns_name_t **namep) {
result = dns_message_gettempname(msg, namep);
check_result(result, "dns_message_gettempname");
result = isc_buffer_allocate(gmctx, &namebuf, DNS_NAME_MAXWIRE);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(gmctx, &namebuf, DNS_NAME_MAXWIRE);
dns_name_init(*namep, NULL);
dns_name_setbuffer(*namep, namebuf);
dns_message_takebuffer(msg, &namebuf);
@ -1284,16 +1283,14 @@ parse_rdata(char **cmdlinep, dns_rdataclass_t rdataclass,
isc_buffer_add(&source, strlen(cmdline));
result = isc_lex_openbuffer(lex, &source);
check_result(result, "isc_lex_openbuffer");
result = isc_buffer_allocate(gmctx, &buf, MAXWIRE);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(gmctx, &buf, MAXWIRE);
result = dns_rdata_fromtext(NULL, rdataclass, rdatatype, lex,
dns_rootname, 0, gmctx, buf,
&callbacks);
isc_lex_destroy(&lex);
if (result == ISC_R_SUCCESS) {
isc_buffer_usedregion(buf, &r);
result = isc_buffer_allocate(gmctx, &newbuf, r.length);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(gmctx, &newbuf, r.length);
isc_buffer_putmem(newbuf, r.base, r.length);
isc_buffer_usedregion(newbuf, &r);
dns_rdata_fromregion(rdata, rdataclass, rdatatype, &r);
@ -2041,8 +2038,7 @@ show_message(FILE *stream, dns_message_t *msg, const char *description) {
}
if (buf != NULL)
isc_buffer_free(&buf);
result = isc_buffer_allocate(gmctx, &buf, bufsz);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(gmctx, &buf, bufsz);
result = dns_message_totext(msg, style, 0, buf);
bufsz *= 2;
} while (result == ISC_R_NOSPACE);

View file

@ -965,8 +965,7 @@ main(int argc, char **argv) {
command = *argv;
DO("allocate data buffer",
isc_buffer_allocate(rndc_mctx, &databuf, 2048));
isc_buffer_allocate(rndc_mctx, &databuf, 2048);
/*
* Convert argc/argv into a space-delimited command string

View file

@ -175,8 +175,7 @@ main(int argc, char *argv[]) {
} else
f = stdin;
result = isc_buffer_allocate(mctx, &input, 64 * 1024);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
isc_buffer_allocate(mctx, &input, 64 * 1024);
if (rawdata) {
while (fread(&c, 1, 1, f) != 0) {

View file

@ -309,8 +309,7 @@ recvresponse(isc_task_t *task, isc_event_t *event) {
if (!display_comments)
flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
result = isc_buffer_allocate(mctx, &buf, len);
CHECK("isc_buffer_allocate", result);
isc_buffer_allocate(mctx, &buf, len);
if (yaml) {
char sockstr[ISC_SOCKADDR_FORMATSIZE];
@ -416,11 +415,8 @@ repopulate_buffer:
buftoosmall:
len += OUTPUTBUF;
isc_buffer_free(&buf);
result = isc_buffer_allocate(mctx, &buf, len);
if (result == ISC_R_SUCCESS)
goto repopulate_buffer;
else
goto cleanup;
isc_buffer_allocate(mctx, &buf, len);
goto repopulate_buffer;
}
CHECK("dns_message_pseudosectiontotext", result);
}

View file

@ -1239,10 +1239,8 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
result = dns_rdata_tostruct(&rdata, &rdata_apl, zone->catzs->mctx);
if (result != ISC_R_SUCCESS)
return (result);
result = isc_buffer_allocate(zone->catzs->mctx, &aclb, 16);
isc_buffer_allocate(zone->catzs->mctx, &aclb, 16);
isc_buffer_setautorealloc(aclb, true);
if (result != ISC_R_SUCCESS)
goto cleanup;
for (result = dns_rdata_apl_first(&rdata_apl);
result == ISC_R_SUCCESS;
result = dns_rdata_apl_next(&rdata_apl)) {
@ -1462,12 +1460,9 @@ dns_catz_generate_masterfilename(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
REQUIRE(entry != NULL);
REQUIRE(buffer != NULL && *buffer != NULL);
result = isc_buffer_allocate(zone->catzs->mctx, &tbuf,
strlen(zone->catzs->view->name) +
2 * DNS_NAME_FORMATSIZE + 2);
if (result != ISC_R_SUCCESS)
return (result);
INSIST(tbuf != NULL);
isc_buffer_allocate(zone->catzs->mctx, &tbuf,
strlen(zone->catzs->view->name) + 2 *
DNS_NAME_FORMATSIZE + 2);
isc_buffer_putstr(tbuf, zone->catzs->view->name);
isc_buffer_putstr(tbuf, "_");
@ -1552,11 +1547,7 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
* The buffer will be reallocated if something won't fit,
* ISC_BUFFER_INCR seems like a good start.
*/
result = isc_buffer_allocate(zone->catzs->mctx, &buffer,
ISC_BUFFER_INCR);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
isc_buffer_allocate(zone->catzs->mctx, &buffer, ISC_BUFFER_INCR);
isc_buffer_setautorealloc(buffer, true);
isc_buffer_putstr(buffer, "zone ");

View file

@ -2556,9 +2556,7 @@ copy_name(isc_mem_t *mctx, dns_message_t *msg, const dns_name_t *name,
result = dns_message_gettempname(msg, &newname);
if (result != ISC_R_SUCCESS)
return (result);
result = isc_buffer_allocate(mctx, &namebuf, DNS_NAME_MAXWIRE);
if (result != ISC_R_SUCCESS)
goto fail;
isc_buffer_allocate(mctx, &namebuf, DNS_NAME_MAXWIRE);
dns_name_init(newname, NULL);
dns_name_setbuffer(newname, namebuf);
dns_message_takebuffer(msg, &namebuf);
@ -2587,10 +2585,7 @@ copy_name(isc_mem_t *mctx, dns_message_t *msg, const dns_name_t *name,
goto fail;
dns_rdata_toregion(&rdata, &r);
rdatabuf = NULL;
result = isc_buffer_allocate(mctx, &rdatabuf,
r.length);
if (result != ISC_R_SUCCESS)
goto fail;
isc_buffer_allocate(mctx, &rdatabuf, r.length);
isc_buffer_putmem(rdatabuf, r.base, r.length);
isc_buffer_usedregion(rdatabuf, &r);
dns_rdata_init(newrdata);

View file

@ -257,9 +257,7 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key,
*/
sig.signature = isc_mem_get(mctx, sig.siglen);
ret = isc_buffer_allocate(mctx, &databuf, sigsize + 256 + 18);
if (ret != ISC_R_SUCCESS)
goto cleanup_signature;
isc_buffer_allocate(mctx, &databuf, sigsize + 256 + 18);
dns_rdata_init(&tmpsigrdata);
ret = dns_rdata_fromstruct(&tmpsigrdata, sig.common.rdclass,
@ -355,7 +353,6 @@ cleanup_context:
dst_context_destroy(&ctx);
cleanup_databuf:
isc_buffer_free(&databuf);
cleanup_signature:
isc_mem_put(mctx, sig.signature, sig.siglen);
return (ret);
@ -997,7 +994,7 @@ dns_dnssec_signmessage(dns_message_t *msg, dst_key_t *key) {
rdata = NULL;
RETERR(dns_message_gettemprdata(msg, &rdata));
RETERR(isc_buffer_allocate(msg->mctx, &dynbuf, 1024));
isc_buffer_allocate(msg->mctx, &dynbuf, 1024);
RETERR(dns_rdata_fromstruct(rdata, dns_rdataclass_any,
dns_rdatatype_sig /* SIG(0) */,
&sig, dynbuf));

View file

@ -865,8 +865,8 @@ dst_key_fromgssapi(const dns_name_t *name, gss_ctx_id_t gssctx,
* Keep the token for use by external ssu rules. They may need
* to examine the PAC in the kerberos ticket.
*/
RETERR(isc_buffer_allocate(key->mctx, &key->key_tkeytoken,
intoken->length));
isc_buffer_allocate(key->mctx, &key->key_tkeytoken,
intoken->length);
RETERR(isc_buffer_copyregion(key->key_tkeytoken, intoken));
}

View file

@ -54,18 +54,12 @@ struct dst_gssapi_signverifyctx {
static isc_result_t
gssapi_create_signverify_ctx(dst_key_t *key, dst_context_t *dctx) {
dst_gssapi_signverifyctx_t *ctx;
isc_result_t result;
UNUSED(key);
ctx = isc_mem_get(dctx->mctx, sizeof(dst_gssapi_signverifyctx_t));
ctx->buffer = NULL;
result = isc_buffer_allocate(dctx->mctx, &ctx->buffer,
INITIAL_BUFFER_SIZE);
if (result != ISC_R_SUCCESS) {
isc_mem_put(dctx->mctx, ctx, sizeof(dst_gssapi_signverifyctx_t));
return (result);
}
isc_buffer_allocate(dctx->mctx, &ctx->buffer, INITIAL_BUFFER_SIZE);
dctx->ctxdata.gssctx = ctx;
@ -107,9 +101,7 @@ gssapi_adddata(dst_context_t *dctx, const isc_region_t *data) {
length = isc_buffer_length(ctx->buffer) + data->length + BUFFER_EXTRA;
result = isc_buffer_allocate(dctx->mctx, &newbuffer, length);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(dctx->mctx, &newbuffer, length);
isc_buffer_usedregion(ctx->buffer, &r);
(void)isc_buffer_copyregion(newbuffer, &r);
@ -276,9 +268,7 @@ gssapi_restore(dst_key_t *key, const char *keystr) {
len = (len / 4) * 3;
result = isc_buffer_allocate(key->mctx, &b, len);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(key->mctx, &b, len);
result = isc_base64_decodestring(keystr, b);
if (result != ISC_R_SUCCESS) {

View file

@ -752,8 +752,8 @@ dst_gssapi_acceptctx(gss_cred_id_t cred,
}
if (gouttoken.length > 0U) {
RETERR(isc_buffer_allocate(mctx, outtoken,
(unsigned int)gouttoken.length));
isc_buffer_allocate(mctx, outtoken,
(unsigned int)gouttoken.length);
GBUFFER_TO_REGION(gouttoken, r);
RETERR(isc_buffer_copyregion(*outtoken, &r));
(void)gss_release_buffer(&minor, &gouttoken);

View file

@ -592,9 +592,7 @@ dns_keytable_dump(dns_keytable_t *keytable, FILE *fp) {
REQUIRE(VALID_KEYTABLE(keytable));
REQUIRE(fp != NULL);
result = isc_buffer_allocate(keytable->mctx, &text, 4096);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(keytable->mctx, &text, 4096);
result = dns_keytable_totext(keytable, &text);

View file

@ -243,13 +243,10 @@ msgblock_free(isc_mem_t *mctx, dns_msgblock_t *block, unsigned int sizeof_type)
*/
static inline isc_result_t
newbuffer(dns_message_t *msg, unsigned int size) {
isc_result_t result;
isc_buffer_t *dynbuf;
dynbuf = NULL;
result = isc_buffer_allocate(msg->mctx, &dynbuf, size);
if (result != ISC_R_SUCCESS)
return (ISC_R_NOMEMORY);
isc_buffer_allocate(msg->mctx, &dynbuf, size);
ISC_LIST_APPEND(msg->scratchpad, dynbuf, link);
return (ISC_R_SUCCESS);
@ -702,7 +699,6 @@ isc_result_t
dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp)
{
dns_message_t *m;
isc_result_t result;
isc_buffer_t *dynbuf;
unsigned int i;
@ -755,33 +751,13 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp)
isc_mempool_setname(m->rdspool, "msg:rdataset");
dynbuf = NULL;
result = isc_buffer_allocate(mctx, &dynbuf, SCRATCHPAD_SIZE);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(mctx, &dynbuf, SCRATCHPAD_SIZE);
ISC_LIST_APPEND(m->scratchpad, dynbuf, link);
m->cctx = NULL;
*msgp = m;
return (ISC_R_SUCCESS);
/*
* Cleanup for error returns.
*/
cleanup:
dynbuf = ISC_LIST_HEAD(m->scratchpad);
if (dynbuf != NULL) {
ISC_LIST_UNLINK(m->scratchpad, dynbuf, link);
isc_buffer_free(&dynbuf);
}
if (m->namepool != NULL)
isc_mempool_destroy(&m->namepool);
if (m->rdspool != NULL)
isc_mempool_destroy(&m->rdspool);
m->magic = 0;
isc_mem_putanddetach(&mctx, m, sizeof(dns_message_t));
return (ISC_R_NOMEMORY);
}
void
@ -2861,9 +2837,7 @@ dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) {
goto cleanup;
isc_buffer_usedregion(querytsig, &r);
result = isc_buffer_allocate(msg->mctx, &buf, r.length);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(msg->mctx, &buf, r.length);
isc_buffer_putmem(buf, r.base, r.length);
isc_buffer_usedregion(buf, &r);
dns_rdata_init(rdata);
@ -2908,9 +2882,7 @@ dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx,
dns_rdataset_current(msg->tsig, &rdata);
dns_rdata_toregion(&rdata, &r);
result = isc_buffer_allocate(mctx, querytsig, r.length);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(mctx, querytsig, r.length);
isc_buffer_putmem(*querytsig, r.base, r.length);
return (ISC_R_SUCCESS);
}
@ -3029,9 +3001,7 @@ dns_message_signer(dns_message_t *msg, dns_name_t *signer) {
if (!dns_name_hasbuffer(signer)) {
isc_buffer_t *dynbuf = NULL;
result = isc_buffer_allocate(msg->mctx, &dynbuf, 512);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(msg->mctx, &dynbuf, 512);
dns_name_setbuffer(signer, dynbuf);
dns_message_takebuffer(msg, &dynbuf);
}
@ -4475,9 +4445,7 @@ dns_message_buildopt(dns_message_t *message, dns_rdataset_t **rdatasetp,
goto cleanup;
}
result = isc_buffer_allocate(message->mctx, &buf, len);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(message->mctx, &buf, len);
for (i = 0; i < count; i++) {
if (ednsopts[i].code == DNS_OPT_PAD &&

View file

@ -568,9 +568,7 @@ dns_ntatable_dump(dns_ntatable_t *ntatable, FILE *fp) {
isc_buffer_t *text = NULL;
int len = 4096;
result = isc_buffer_allocate(ntatable->view->mctx, &text, len);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(ntatable->view->mctx, &text, len);
result = dns_ntatable_totext(ntatable, NULL, &text);

View file

@ -273,16 +273,15 @@ static isc_result_t openssleddsa_todns(const dst_key_t *key,
static isc_result_t
openssleddsa_createctx(dst_key_t *key, dst_context_t *dctx) {
isc_buffer_t *buf = NULL;
isc_result_t result;
UNUSED(key);
REQUIRE(dctx->key->key_alg == DST_ALG_ED25519 ||
dctx->key->key_alg == DST_ALG_ED448);
result = isc_buffer_allocate(dctx->mctx, &buf, 64);
isc_buffer_allocate(dctx->mctx, &buf, 64);
dctx->ctxdata.generic = buf;
return (result);
return (ISC_R_SUCCESS);
}
static void
@ -312,9 +311,7 @@ openssleddsa_adddata(dst_context_t *dctx, const isc_region_t *data) {
return (ISC_R_SUCCESS);
length = isc_buffer_length(buf) + data->length + 64;
result = isc_buffer_allocate(dctx->mctx, &nbuf, length);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(dctx->mctx, &nbuf, length);
isc_buffer_usedregion(buf, &r);
(void) isc_buffer_copyregion(nbuf, &r);
(void) isc_buffer_copyregion(nbuf, data);

View file

@ -108,9 +108,7 @@ pkcs11eddsa_adddata(dst_context_t *dctx, const isc_region_t *data) {
return (ISC_R_SUCCESS);
length = isc_buffer_length(buf) + data->length + 64;
result = isc_buffer_allocate(dctx->mctx, &nbuf, length);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(dctx->mctx, &nbuf, length);
isc_buffer_usedregion(buf, &r);
(void) isc_buffer_copyregion(nbuf, &r);
(void) isc_buffer_copyregion(nbuf, data);

View file

@ -9884,10 +9884,7 @@ restart:
dns_rdataset_t *sigrdataset_aaaa = NULL;
dns_name_t *gluename = dns_fixedname_name(&ge->fixedname);
result = isc_buffer_allocate(msg->mctx, &buffer, 512);
if (ISC_UNLIKELY(result != ISC_R_SUCCESS)) {
goto no_glue;
}
isc_buffer_allocate(msg->mctx, &buffer, 512);
result = dns_message_gettempname(msg, &name);
if (ISC_UNLIKELY(result != ISC_R_SUCCESS)) {

View file

@ -857,9 +857,7 @@ unknown_fromtext(dns_rdataclass_t rdclass, dns_rdatatype_t type,
false));
if (token.value.as_ulong > 65535U)
return (ISC_R_RANGE);
result = isc_buffer_allocate(mctx, &buf, token.value.as_ulong);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(mctx, &buf, token.value.as_ulong);
if (token.value.as_ulong != 0U) {
result = isc_hex_tobuffer(lexer, buf,

View file

@ -780,10 +780,7 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
sock = req_getsocket(request);
INSIST(sock != NULL);
result = isc_buffer_allocate(mctx, &request->query,
r.length + (tcp ? 2 : 0));
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(mctx, &request->query, r.length + (tcp ? 2 : 0));
if (tcp)
isc_buffer_putuint16(request->query, (uint16_t)r.length);
result = isc_buffer_copyregion(request->query, &r);
@ -1040,9 +1037,7 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp,
/*
* Create buffer able to hold largest possible message.
*/
result = isc_buffer_allocate(mctx, &buf1, 65535);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(mctx, &buf1, 65535);
result = dns_compress_init(&cctx, -1, mctx);
if (result != ISC_R_SUCCESS)
@ -1087,9 +1082,7 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp,
result = DNS_R_USETCP;
goto cleanup;
}
result = isc_buffer_allocate(mctx, &buf2, r.length + (tcp ? 2 : 0));
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(mctx, &buf2, r.length + (tcp ? 2 : 0));
if (tcp)
isc_buffer_putuint16(buf2, (uint16_t)r.length);
result = isc_buffer_copyregion(buf2, &r);
@ -1348,10 +1341,7 @@ req_response(isc_task_t *task, isc_event_t *event) {
* Copy buffer to request.
*/
isc_buffer_usedregion(&devent->buffer, &r);
result = isc_buffer_allocate(request->mctx, &request->answer,
r.length);
if (result != ISC_R_SUCCESS)
goto done;
isc_buffer_allocate(request->mctx, &request->answer, r.length);
result = isc_buffer_copyregion(request->answer, &r);
if (result != ISC_R_SUCCESS)
isc_buffer_free(&request->answer);

View file

@ -273,7 +273,6 @@ dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval,
dns_rdatalist_t *rdatalist;
dns_rdata_t *rdata;
isc_buffer_t *rdatabuf = NULL;
isc_result_t result;
isc_mem_t *mctx;
isc_region_t region;
@ -299,9 +298,7 @@ dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval,
rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
result = isc_buffer_allocate(mctx, &rdatabuf, rdlen);
if (result != ISC_R_SUCCESS)
goto failure;
isc_buffer_allocate(mctx, &rdatabuf, rdlen);
DE_CONST(rdatap, region.base);
region.length = rdlen;
isc_buffer_copyregion(rdatabuf, &region);
@ -311,12 +308,8 @@ dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval,
&region);
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
ISC_LIST_APPEND(lookup->buffers, rdatabuf, link);
rdata = NULL;
failure:
if (rdata != NULL)
isc_mem_put(mctx, rdata, sizeof(dns_rdata_t));
return (result);
return (ISC_R_SUCCESS);
}
isc_result_t

View file

@ -1076,9 +1076,7 @@ modrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
mctx = sdlz->common.mctx;
result = isc_buffer_allocate(mctx, &buffer, 1024);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(mctx, &buffer, 1024);
result = dns_master_stylecreate(&style, 0, 0, 0, 0, 0, 0, 1,
0xffffffff, mctx);
@ -1869,9 +1867,7 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl,
goto failure;
rdatabuf = NULL;
result = isc_buffer_allocate(mctx, &rdatabuf, size);
if (result != ISC_R_SUCCESS)
goto failure;
isc_buffer_allocate(mctx, &rdatabuf, size);
result = dns_rdata_fromtext(rdata, rdatalist->rdclass,
rdatalist->type, lex,

View file

@ -571,8 +571,7 @@ dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname) {
name = dns_fixedname_initname(fname);
result = isc_buffer_allocate(dt_mctx, &b, length);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(dt_mctx, &b, length);
isc_buffer_putmem(b, (const unsigned char *) namestr, length);
result = dns_name_fromtext(name, b, dns_rootname, 0, NULL);

View file

@ -141,7 +141,7 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) {
tsig.siglen = isc_buffer_usedlength(&sigbuf);
assert_int_equal(sigsize, tsig.siglen);
CHECK(isc_buffer_allocate(dt_mctx, &dynbuf, 512));
isc_buffer_allocate(dt_mctx, &dynbuf, 512);
CHECK(dns_rdata_fromstruct(&rdata, dns_rdataclass_any,
dns_rdatatype_tsig, &tsig, dynbuf));
dns_rdatalist_init(&rdatalist);
@ -312,16 +312,14 @@ tsig_tcp_test(void **state) {
/*
* Create request.
*/
result = isc_buffer_allocate(dt_mctx, &buf, 65535);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(dt_mctx, &buf, 65535);
render(buf, 0, key, &tsigout, &querytsig, NULL);
isc_buffer_free(&buf);
/*
* Create response message 1.
*/
result = isc_buffer_allocate(dt_mctx, &buf, 65535);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(dt_mctx, &buf, 65535);
render(buf, DNS_MESSAGEFLAG_QR, key, &querytsig, &tsigout, NULL);
/*
@ -374,8 +372,7 @@ tsig_tcp_test(void **state) {
/*
* Create response message 2.
*/
result = isc_buffer_allocate(dt_mctx, &buf, 65535);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(dt_mctx, &buf, 65535);
assert_int_equal(result, ISC_R_SUCCESS);
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
@ -421,8 +418,7 @@ tsig_tcp_test(void **state) {
/*
* Create response message 3.
*/
result = isc_buffer_allocate(dt_mctx, &buf, 65535);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(dt_mctx, &buf, 65535);
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
result = add_tsig(outctx, key, buf);

View file

@ -164,7 +164,7 @@ add_rdata_to_list(dns_message_t *msg, dns_name_t *name, dns_rdata_t *rdata,
RETERR(dns_message_gettemprdata(msg, &newrdata));
dns_rdata_toregion(rdata, &r);
RETERR(isc_buffer_allocate(msg->mctx, &tmprdatabuf, r.length));
isc_buffer_allocate(msg->mctx, &tmprdatabuf, r.length);
isc_buffer_availableregion(tmprdatabuf, &newr);
memmove(newr.base, r.base, r.length);
dns_rdata_fromregion(newrdata, rdata->rdclass, rdata->type, &newr);
@ -438,7 +438,7 @@ process_dhtkey(dns_message_t *msg, dns_name_t *signer, dns_name_t *name,
RETERR(add_rdata_to_list(msg, &ourname, &ourkeyrdata, 0, namelist));
RETERR(dst_key_secretsize(tctx->dhkey, &sharedsize));
RETERR(isc_buffer_allocate(msg->mctx, &shared, sharedsize));
isc_buffer_allocate(msg->mctx, &shared, sharedsize);
result = dst_key_computesecret(pubkey, tctx->dhkey, shared);
if (result != ISC_R_SUCCESS) {
@ -940,9 +940,9 @@ buildquery(dns_message_t *msg, const dns_name_t *name,
dns_rdatatype_tkey);
len = 16 + tkey->algorithm.length + tkey->keylen + tkey->otherlen;
RETERR(isc_buffer_allocate(msg->mctx, &dynbuf, len));
RETERR(isc_buffer_allocate(msg->mctx, &anamebuf, name->length));
RETERR(isc_buffer_allocate(msg->mctx, &qnamebuf, name->length));
isc_buffer_allocate(msg->mctx, &dynbuf, len);
isc_buffer_allocate(msg->mctx, &anamebuf, name->length);
isc_buffer_allocate(msg->mctx, &qnamebuf, name->length);
RETERR(dns_message_gettemprdata(msg, &rdata));
RETERR(dns_rdata_fromstruct(rdata, dns_rdataclass_any,
@ -1046,7 +1046,7 @@ dns_tkey_builddhquery(dns_message_t *msg, dst_key_t *key,
RETERR(buildquery(msg, name, &tkey, false));
RETERR(dns_message_gettemprdata(msg, &rdata));
RETERR(isc_buffer_allocate(msg->mctx, &dynbuf, 1024));
isc_buffer_allocate(msg->mctx, &dynbuf, 1024);
RETERR(dst_key_todns(key, dynbuf));
isc_buffer_usedregion(dynbuf, &r);
dns_rdata_fromregion(rdata, dns_rdataclass_any,
@ -1265,7 +1265,7 @@ dns_tkey_processdhresponse(dns_message_t *qmsg, dns_message_t *rmsg,
rmsg->mctx, &theirkey));
RETERR(dst_key_secretsize(key, &sharedsize));
RETERR(isc_buffer_allocate(rmsg->mctx, &shared, sharedsize));
isc_buffer_allocate(rmsg->mctx, &shared, sharedsize);
RETERR(dst_key_computesecret(theirkey, key, shared));

View file

@ -975,9 +975,7 @@ dns_tsig_sign(dns_message_t *msg) {
ret = dns_message_gettemprdata(msg, &rdata);
if (ret != ISC_R_SUCCESS)
goto cleanup_signature;
ret = isc_buffer_allocate(msg->mctx, &dynbuf, 512);
if (ret != ISC_R_SUCCESS)
goto cleanup_rdata;
isc_buffer_allocate(msg->mctx, &dynbuf, 512);
ret = dns_rdata_fromstruct(rdata, dns_rdataclass_any,
dns_rdatatype_tsig, &tsig, dynbuf);
if (ret != ISC_R_SUCCESS)

View file

@ -13822,9 +13822,7 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags,
goto soa_cleanup;
dns_rdataset_current(&rdataset, &rdata);
dns_rdata_toregion(&rdata, &r);
result = isc_buffer_allocate(zone->mctx, &b, r.length);
if (result != ISC_R_SUCCESS)
goto soa_cleanup;
isc_buffer_allocate(zone->mctx, &b, r.length);
isc_buffer_putmem(b, r.base, r.length);
isc_buffer_usedregion(b, &r);
dns_rdata_init(temprdata);
@ -16712,9 +16710,7 @@ dns_zone_forwardupdate(dns_zone_t *zone, dns_message_t *msg,
goto cleanup;
}
result = isc_buffer_allocate(zone->mctx, &forward->msgbuf, mr->length);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(zone->mctx, &forward->msgbuf, mr->length);
result = isc_buffer_copyregion(forward->msgbuf, mr);
if (result != ISC_R_SUCCESS)
goto cleanup;

View file

@ -109,11 +109,7 @@ configure_key(isc_mem_t *mctx, const cfg_obj_t *key, irs_dnsconf_t *conf,
return (result);
}
isc_buffer_usedregion(&rrdatabuf, &r);
result = isc_buffer_allocate(mctx, &keydatabuf,
r.length);
if (result != ISC_R_SUCCESS) {
return (result);
}
isc_buffer_allocate(mctx, &keydatabuf, r.length);
result = isc_buffer_copyregion(keydatabuf, &r);
if (result != ISC_R_SUCCESS) {
goto cleanup;

View file

@ -500,9 +500,7 @@ isc_buffer_dup(isc_mem_t *mctx, isc_buffer_t **dstp, const isc_buffer_t *src) {
isc_buffer_usedregion(src, &region);
result = isc_buffer_allocate(mctx, &dst, region.length);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(mctx, &dst, region.length);
result = isc_buffer_copyregion(dst, &region);
RUNTIME_CHECK(result == ISC_R_SUCCESS); /* NOSPACE is impossible */

View file

@ -181,7 +181,6 @@ new_source(isc_lex_t *lex, bool is_file, bool need_close,
void *input, const char *name)
{
inputsource *source;
isc_result_t result;
source = isc_mem_get(lex->mctx, sizeof(*source));
source->result = ISC_R_SUCCESS;
@ -192,13 +191,8 @@ new_source(isc_lex_t *lex, bool is_file, bool need_close,
source->input = input;
source->name = isc_mem_strdup(lex->mctx, name);
source->pushback = NULL;
result = isc_buffer_allocate(lex->mctx, &source->pushback,
(unsigned int)lex->max_token);
if (result != ISC_R_SUCCESS) {
isc_mem_free(lex->mctx, source->name);
isc_mem_put(lex->mctx, source, sizeof(*source));
return (result);
}
isc_buffer_allocate(lex->mctx, &source->pushback,
(unsigned int)lex->max_token);
source->ignored = 0;
source->line = 1;
ISC_LIST_INITANDPREPEND(lex->sources, source, link);
@ -320,9 +314,7 @@ pushandgrow(isc_lex_t *lex, inputsource *source, int c) {
isc_result_t result;
oldlen = isc_buffer_length(source->pushback);
result = isc_buffer_allocate(lex->mctx, &tbuf, oldlen * 2);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_allocate(lex->mctx, &tbuf, oldlen * 2);
isc_buffer_usedregion(source->pushback, &used);
result = isc_buffer_copyregion(tbuf, &used);
INSIST(result == ISC_R_SUCCESS);

View file

@ -65,8 +65,7 @@ isc_buffer_reserve_test(void **state) {
UNUSED(state);
b = NULL;
result = isc_buffer_allocate(test_mctx, &b, 1024);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(test_mctx, &b, 1024);
assert_int_equal(b->length, 1024);
/*
@ -127,7 +126,6 @@ isc_buffer_reserve_test(void **state) {
/* dynamic buffer automatic reallocation */
static void
isc_buffer_dynamic_test(void **state) {
isc_result_t result;
isc_buffer_t *b;
size_t last_length = 10;
int i;
@ -135,8 +133,7 @@ isc_buffer_dynamic_test(void **state) {
UNUSED(state);
b = NULL;
result = isc_buffer_allocate(test_mctx, &b, last_length);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(test_mctx, &b, last_length);
assert_non_null(b);
assert_int_equal(b->length, last_length);
@ -194,8 +191,7 @@ isc_buffer_copyregion_test(void **state) {
UNUSED(state);
result = isc_buffer_allocate(test_mctx, &b, sizeof(data));
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(test_mctx, &b, sizeof(data));
/*
* Fill originally allocated buffer space.
@ -234,8 +230,7 @@ isc_buffer_printf_test(void **state) {
* Prepare a buffer with auto-reallocation enabled.
*/
b = NULL;
result = isc_buffer_allocate(test_mctx, &b, 0);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_allocate(test_mctx, &b, 0);
isc_buffer_setautorealloc(b, true);
/*

View file

@ -2858,17 +2858,11 @@ ns_client_putrdataset(ns_client_t *client, dns_rdataset_t **rdatasetp) {
isc_result_t
ns_client_newnamebuf(ns_client_t *client) {
isc_buffer_t *dbuf;
isc_result_t result;
CTRACE("ns_client_newnamebuf");
dbuf = NULL;
result = isc_buffer_allocate(client->mctx, &dbuf, 1024);
if (result != ISC_R_SUCCESS) {
CTRACE("ns_client_newnamebuf: "
"isc_buffer_allocate failed: done");
return (result);
}
isc_buffer_allocate(client->mctx, &dbuf, 1024);
ISC_LIST_APPEND(client->query.namebufs, dbuf, link);
CTRACE("ns_client_newnamebuf: done");

View file

@ -7458,11 +7458,9 @@ query_dns64(query_ctx_t *qctx) {
isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
result = isc_buffer_allocate(client->mctx, &buffer,
view->dns64cnt * 16 *
dns_rdataset_count(qctx->rdataset));
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(client->mctx, &buffer,
view->dns64cnt * 16 *
dns_rdataset_count(qctx->rdataset));
result = dns_message_gettemprdataset(client->message,
&dns64_rdataset);
if (result != ISC_R_SUCCESS)
@ -7628,10 +7626,8 @@ query_filter64(query_ctx_t *qctx) {
client->query.attributes &= ~NS_QUERYATTR_SECURE;
}
result = isc_buffer_allocate(client->mctx, &buffer,
16 * dns_rdataset_count(qctx->rdataset));
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_buffer_allocate(client->mctx, &buffer,
16 * dns_rdataset_count(qctx->rdataset));
result = dns_message_gettemprdataset(client->message, &myrdataset);
if (result != ISC_R_SUCCESS)
goto cleanup;

View file

@ -236,11 +236,7 @@ main(int argc, char *argv[]) {
/* Dump the response */
outputbuf = NULL;
result = isc_buffer_allocate(mctx, &outputbuf, 65535);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "failed to allocate a result buffer\n");
exit(1);
}
isc_buffer_allocate(mctx, &outputbuf, 65535);
for (i = 0; i < DNS_SECTION_MAX; i++) {
print_section(rmessage, i, outputbuf);
isc_buffer_clear(outputbuf);

View file

@ -443,16 +443,14 @@ parse_rdata(isc_mem_t *mctx, char **cmdlinep, dns_rdataclass_t rdataclass,
isc_buffer_add(&source, strlen(cmdline));
result = isc_lex_openbuffer(lex, &source);
check_result(result, "isc_lex_openbuffer");
result = isc_buffer_allocate(mctx, &buf, MAXWIRE);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &buf, MAXWIRE);
result = dns_rdata_fromtext(rdata, rdataclass, rdatatype, lex,
dns_rootname, 0, mctx, buf,
&callbacks);
isc_lex_destroy(&lex);
if (result == ISC_R_SUCCESS) {
isc_buffer_usedregion(buf, &r);
result = isc_buffer_allocate(mctx, &newbuf, r.length);
check_result(result, "isc_buffer_allocate");
isc_buffer_allocate(mctx, &newbuf, r.length);
isc_buffer_putmem(newbuf, r.base, r.length);
isc_buffer_usedregion(newbuf, &r);
dns_rdata_reset(rdata);