mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
avoid the 'target' buffer in dns_name_fromtext()
dns_name_fromtext() stores the converted name in the 'name' passed to it, and optionally also copies it in wire format to a buffer 'target'. this makes the interface unnecessarily complex, and could be simplified by having a different function for each purpose. as a first step, remove uses of the target buffer in calls to dns_name_fromtext() where it wasn't actually needed.
This commit is contained in:
@@ -858,14 +858,14 @@ requeue_lookup(dig_lookup_t *lookold, bool servers) {
|
||||
void
|
||||
setup_text_key(void) {
|
||||
isc_result_t result;
|
||||
dns_name_t keyname;
|
||||
dns_fixedname_t fkey;
|
||||
dns_name_t *keyname = dns_fixedname_initname(&fkey);
|
||||
isc_buffer_t secretbuf;
|
||||
unsigned int secretsize;
|
||||
unsigned char *secretstore;
|
||||
|
||||
debug("setup_text_key()");
|
||||
isc_buffer_allocate(mctx, &namebuf, MXNAME);
|
||||
dns_name_init(&keyname);
|
||||
isc_buffer_putstr(namebuf, keynametext);
|
||||
secretsize = (unsigned int)strlen(keysecret) * 3 / 4;
|
||||
secretstore = isc_mem_allocate(mctx, secretsize);
|
||||
@@ -882,12 +882,12 @@ setup_text_key(void) {
|
||||
goto failure;
|
||||
}
|
||||
|
||||
result = dns_name_fromtext(&keyname, namebuf, dns_rootname, 0, namebuf);
|
||||
result = dns_name_fromtext(keyname, namebuf, dns_rootname, 0, NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto failure;
|
||||
}
|
||||
|
||||
result = dns_tsigkey_create(&keyname, hmac_alg, secretstore,
|
||||
result = dns_tsigkey_create(keyname, hmac_alg, secretstore,
|
||||
(int)secretsize, mctx, &tsigkey);
|
||||
failure:
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
@@ -898,7 +898,6 @@ failure:
|
||||
}
|
||||
|
||||
isc_mem_free(mctx, secretstore);
|
||||
dns_name_invalidate(&keyname);
|
||||
isc_buffer_free(&namebuf);
|
||||
}
|
||||
|
||||
|
@@ -27,17 +27,16 @@
|
||||
#include <named/log.h>
|
||||
#include <named/transportconf.h>
|
||||
|
||||
#define create_name(id, name) \
|
||||
isc_buffer_t namesrc, namebuf; \
|
||||
char namedata[DNS_NAME_FORMATSIZE + 1]; \
|
||||
dns_name_init(name); \
|
||||
isc_buffer_constinit(&namesrc, id, strlen(id)); \
|
||||
isc_buffer_add(&namesrc, strlen(id)); \
|
||||
isc_buffer_init(&namebuf, namedata, sizeof(namedata)); \
|
||||
result = (dns_name_fromtext(name, &namesrc, dns_rootname, \
|
||||
DNS_NAME_DOWNCASE, &namebuf)); \
|
||||
if (result != ISC_R_SUCCESS) { \
|
||||
goto failure; \
|
||||
#define create_name(id, name) \
|
||||
isc_buffer_t namesrc; \
|
||||
dns_fixedname_t _fn; \
|
||||
name = dns_fixedname_initname(&_fn); \
|
||||
isc_buffer_constinit(&namesrc, id, strlen(id)); \
|
||||
isc_buffer_add(&namesrc, strlen(id)); \
|
||||
result = (dns_name_fromtext(name, &namesrc, dns_rootname, \
|
||||
DNS_NAME_DOWNCASE, NULL)); \
|
||||
if (result != ISC_R_SUCCESS) { \
|
||||
goto failure; \
|
||||
}
|
||||
|
||||
#define parse_transport_option(map, transport, name, setter) \
|
||||
@@ -100,15 +99,15 @@ add_doh_transports(const cfg_obj_t *transportlist, dns_transport_list_t *list) {
|
||||
for (const cfg_listelt_t *element = cfg_list_first(transportlist);
|
||||
element != NULL; element = cfg_list_next(element))
|
||||
{
|
||||
dns_name_t dohname;
|
||||
dns_transport_t *transport;
|
||||
dns_name_t *dohname = NULL;
|
||||
dns_transport_t *transport = NULL;
|
||||
|
||||
doh = cfg_listelt_value(element);
|
||||
dohid = cfg_obj_asstring(cfg_map_getname(doh));
|
||||
|
||||
create_name(dohid, &dohname);
|
||||
create_name(dohid, dohname);
|
||||
|
||||
transport = dns_transport_new(&dohname, DNS_TRANSPORT_HTTP,
|
||||
transport = dns_transport_new(dohname, DNS_TRANSPORT_HTTP,
|
||||
list);
|
||||
|
||||
dns_transport_set_tlsname(transport, dohid);
|
||||
@@ -148,8 +147,8 @@ add_tls_transports(const cfg_obj_t *transportlist, dns_transport_list_t *list) {
|
||||
for (const cfg_listelt_t *element = cfg_list_first(transportlist);
|
||||
element != NULL; element = cfg_list_next(element))
|
||||
{
|
||||
dns_name_t tlsname;
|
||||
dns_transport_t *transport;
|
||||
dns_name_t *tlsname = NULL;
|
||||
dns_transport_t *transport = NULL;
|
||||
|
||||
tls = cfg_listelt_value(element);
|
||||
tlsid = cfg_obj_asstring(cfg_map_getname(tls));
|
||||
@@ -159,10 +158,9 @@ add_tls_transports(const cfg_obj_t *transportlist, dns_transport_list_t *list) {
|
||||
goto failure;
|
||||
}
|
||||
|
||||
create_name(tlsid, &tlsname);
|
||||
create_name(tlsid, tlsname);
|
||||
|
||||
transport = dns_transport_new(&tlsname, DNS_TRANSPORT_TLS,
|
||||
list);
|
||||
transport = dns_transport_new(tlsname, DNS_TRANSPORT_TLS, list);
|
||||
|
||||
dns_transport_set_tlsname(transport, tlsid);
|
||||
parse_transport_option(tls, transport, "key-file",
|
||||
@@ -222,12 +220,12 @@ transport_list_fromconfig(const cfg_obj_t *config, dns_transport_list_t *list) {
|
||||
static void
|
||||
transport_list_add_ephemeral(dns_transport_list_t *list) {
|
||||
isc_result_t result;
|
||||
dns_name_t tlsname;
|
||||
dns_name_t *tlsname = NULL;
|
||||
dns_transport_t *transport;
|
||||
|
||||
create_name("ephemeral", &tlsname);
|
||||
create_name("ephemeral", tlsname);
|
||||
|
||||
transport = dns_transport_new(&tlsname, DNS_TRANSPORT_TLS, list);
|
||||
transport = dns_transport_new(tlsname, DNS_TRANSPORT_TLS, list);
|
||||
dns_transport_set_tlsname(transport, "ephemeral");
|
||||
|
||||
return;
|
||||
|
@@ -46,11 +46,11 @@ add_initial_keys(const cfg_obj_t *list, dns_tsigkeyring_t *ring,
|
||||
{
|
||||
const cfg_obj_t *algobj = NULL;
|
||||
const cfg_obj_t *secretobj = NULL;
|
||||
dns_name_t keyname;
|
||||
dns_fixedname_t fkey;
|
||||
dns_name_t *keyname = dns_fixedname_initname(&fkey);
|
||||
dst_algorithm_t alg = DST_ALG_UNKNOWN;
|
||||
const char *algstr = NULL;
|
||||
char keynamedata[1024];
|
||||
isc_buffer_t keynamesrc, keynamebuf;
|
||||
isc_buffer_t keynamesrc;
|
||||
const char *secretstr = NULL;
|
||||
isc_buffer_t secretbuf;
|
||||
int secretlen = 0;
|
||||
@@ -68,12 +68,10 @@ add_initial_keys(const cfg_obj_t *list, dns_tsigkeyring_t *ring,
|
||||
/*
|
||||
* Create the key name.
|
||||
*/
|
||||
dns_name_init(&keyname);
|
||||
isc_buffer_constinit(&keynamesrc, keyid, strlen(keyid));
|
||||
isc_buffer_add(&keynamesrc, strlen(keyid));
|
||||
isc_buffer_init(&keynamebuf, keynamedata, sizeof(keynamedata));
|
||||
ret = dns_name_fromtext(&keyname, &keynamesrc, dns_rootname,
|
||||
DNS_NAME_DOWNCASE, &keynamebuf);
|
||||
ret = dns_name_fromtext(keyname, &keynamesrc, dns_rootname,
|
||||
DNS_NAME_DOWNCASE, NULL);
|
||||
if (ret != ISC_R_SUCCESS) {
|
||||
goto failure;
|
||||
}
|
||||
@@ -103,7 +101,7 @@ add_initial_keys(const cfg_obj_t *list, dns_tsigkeyring_t *ring,
|
||||
}
|
||||
secretlen = isc_buffer_usedlength(&secretbuf);
|
||||
|
||||
ret = dns_tsigkey_create(&keyname, alg, secret, secretlen, mctx,
|
||||
ret = dns_tsigkey_create(keyname, alg, secret, secretlen, mctx,
|
||||
&tsigkey);
|
||||
isc_mem_put(mctx, secret, secretalloc);
|
||||
secret = NULL;
|
||||
|
@@ -786,16 +786,14 @@ set_source_ports(dns_dispatchmgr_t *manager) {
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
create_name(const char *str, char *namedata, size_t len, dns_name_t *name) {
|
||||
isc_buffer_t namesrc, namebuf;
|
||||
create_name(const char *str, dns_name_t *name) {
|
||||
isc_buffer_t namesrc;
|
||||
|
||||
dns_name_init(name);
|
||||
isc_buffer_constinit(&namesrc, str, strlen(str));
|
||||
isc_buffer_add(&namesrc, strlen(str));
|
||||
isc_buffer_init(&namebuf, namedata, len);
|
||||
|
||||
return dns_name_fromtext(name, &namesrc, dns_rootname,
|
||||
DNS_NAME_DOWNCASE, &namebuf);
|
||||
DNS_NAME_DOWNCASE, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -805,8 +803,8 @@ setup_system(void *arg ISC_ATTR_UNUSED) {
|
||||
isc_sockaddrlist_t *nslist;
|
||||
isc_logconfig_t *logconfig = NULL;
|
||||
irs_resconf_t *resconf = NULL;
|
||||
dns_name_t tlsname;
|
||||
char namedata[DNS_NAME_FORMATSIZE + 1];
|
||||
dns_fixedname_t ftls;
|
||||
dns_name_t *tlsname = dns_fixedname_initname(&ftls);
|
||||
|
||||
ddebug("setup_system()");
|
||||
|
||||
@@ -940,17 +938,15 @@ setup_system(void *arg ISC_ATTR_UNUSED) {
|
||||
isc_tlsctx_cache_create(gmctx, &tls_ctx_cache);
|
||||
|
||||
if (tls_client_key_file == NULL) {
|
||||
result = create_name("tls-non-auth-client", namedata,
|
||||
sizeof(namedata), &tlsname);
|
||||
result = create_name("tls-non-auth-client", tlsname);
|
||||
check_result(result, "create_name (tls-non-auth-client)");
|
||||
transport = dns_transport_new(&tlsname, DNS_TRANSPORT_TLS,
|
||||
transport = dns_transport_new(tlsname, DNS_TRANSPORT_TLS,
|
||||
transport_list);
|
||||
dns_transport_set_tlsname(transport, "tls-non-auth-client");
|
||||
} else {
|
||||
result = create_name("tls-auth-client", namedata,
|
||||
sizeof(namedata), &tlsname);
|
||||
result = create_name("tls-auth-client", tlsname);
|
||||
check_result(result, "create_name (tls-auth-client)");
|
||||
transport = dns_transport_new(&tlsname, DNS_TRANSPORT_TLS,
|
||||
transport = dns_transport_new(tlsname, DNS_TRANSPORT_TLS,
|
||||
transport_list);
|
||||
dns_transport_set_tlsname(transport, "tls-auth-client");
|
||||
dns_transport_set_keyfile(transport, tls_client_key_file);
|
||||
|
@@ -65,7 +65,6 @@ static isc_sockaddr_t tls_connect_addr;
|
||||
|
||||
static isc_tlsctx_cache_t *tls_tlsctx_client_cache = NULL;
|
||||
static isc_tlsctx_t *tls_listen_tlsctx = NULL;
|
||||
static dns_name_t tls_name;
|
||||
static const char *tls_name_str = "ephemeral";
|
||||
static dns_transport_t *tls_transport = NULL;
|
||||
static dns_transport_list_t *transport_list = NULL;
|
||||
@@ -150,8 +149,9 @@ setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
|
||||
|
||||
static int
|
||||
setup_test(void **state) {
|
||||
isc_buffer_t namesrc, namebuf;
|
||||
char namedata[DNS_NAME_FORMATSIZE + 1];
|
||||
isc_buffer_t namesrc;
|
||||
dns_fixedname_t ft;
|
||||
dns_name_t *tls_name = dns_fixedname_initname(&ft);
|
||||
|
||||
uv_os_sock_t socket = -1;
|
||||
|
||||
@@ -216,17 +216,15 @@ setup_test(void **state) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dns_name_init(&tls_name);
|
||||
isc_buffer_constinit(&namesrc, tls_name_str, strlen(tls_name_str));
|
||||
isc_buffer_add(&namesrc, strlen(tls_name_str));
|
||||
isc_buffer_init(&namebuf, namedata, sizeof(namedata));
|
||||
if (dns_name_fromtext(&tls_name, &namesrc, dns_rootname,
|
||||
DNS_NAME_DOWNCASE, &namebuf) != ISC_R_SUCCESS)
|
||||
if (dns_name_fromtext(tls_name, &namesrc, dns_rootname,
|
||||
DNS_NAME_DOWNCASE, NULL) != ISC_R_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
transport_list = dns_transport_list_new(mctx);
|
||||
tls_transport = dns_transport_new(&tls_name, DNS_TRANSPORT_TLS,
|
||||
tls_transport = dns_transport_new(tls_name, DNS_TRANSPORT_TLS,
|
||||
transport_list);
|
||||
dns_transport_set_tlsname(tls_transport, tls_name_str);
|
||||
|
||||
|
@@ -55,9 +55,9 @@ nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...) {
|
||||
static dns_masterrawheader_t header;
|
||||
static bool headerset;
|
||||
|
||||
dns_name_t dns_origin;
|
||||
dns_fixedname_t dns_fixed;
|
||||
dns_name_t *dns_origin = NULL;
|
||||
char origin[sizeof(TEST_ORIGIN)];
|
||||
unsigned char name_buf[BUFLEN];
|
||||
dns_rdatacallbacks_t callbacks;
|
||||
char *include_file = NULL;
|
||||
|
||||
@@ -91,19 +91,16 @@ setup_master(void (*warn)(struct dns_rdatacallbacks *, const char *, ...),
|
||||
isc_result_t result;
|
||||
int len;
|
||||
isc_buffer_t source;
|
||||
isc_buffer_t target;
|
||||
|
||||
dns_origin = dns_fixedname_initname(&dns_fixed);
|
||||
strlcpy(origin, TEST_ORIGIN, sizeof(origin));
|
||||
len = strlen(origin);
|
||||
isc_buffer_init(&source, origin, len);
|
||||
isc_buffer_add(&source, len);
|
||||
isc_buffer_setactive(&source, len);
|
||||
isc_buffer_init(&target, name_buf, BUFLEN);
|
||||
dns_name_init(&dns_origin);
|
||||
dns_master_initrawheader(&header);
|
||||
|
||||
result = dns_name_fromtext(&dns_origin, &source, dns_rootname, 0,
|
||||
&target);
|
||||
result = dns_name_fromtext(dns_origin, &source, dns_rootname, 0, NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -152,7 +149,7 @@ test_master(const char *workdir, const char *testfile,
|
||||
}
|
||||
}
|
||||
|
||||
result = dns_master_loadfile(testfile, &dns_origin, &dns_origin,
|
||||
result = dns_master_loadfile(testfile, dns_origin, dns_origin,
|
||||
dns_rdataclass_in, true, 0, &callbacks,
|
||||
NULL, NULL, mctx, format, 0);
|
||||
|
||||
@@ -327,10 +324,10 @@ ISC_RUN_TEST_IMPL(master_includelist) {
|
||||
result = isc_dir_chdir(SRCDIR);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_master_loadfile(
|
||||
TESTS_DIR "/testdata/master/master8.data", &dns_origin,
|
||||
&dns_origin, dns_rdataclass_in, 0, true, &callbacks,
|
||||
include_callback, &filename, mctx, dns_masterformat_text, 0);
|
||||
result = dns_master_loadfile(TESTS_DIR "/testdata/master/master8.data",
|
||||
dns_origin, dns_origin, dns_rdataclass_in,
|
||||
0, true, &callbacks, include_callback,
|
||||
&filename, mctx, dns_masterformat_text, 0);
|
||||
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
||||
assert_non_null(filename);
|
||||
if (filename != NULL) {
|
||||
@@ -455,26 +452,13 @@ ISC_RUN_TEST_IMPL(dumpraw) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbversion_t *version = NULL;
|
||||
char myorigin[sizeof(TEST_ORIGIN)];
|
||||
dns_name_t dnsorigin;
|
||||
isc_buffer_t source, target;
|
||||
unsigned char namebuf[BUFLEN];
|
||||
int len;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
strlcpy(myorigin, TEST_ORIGIN, sizeof(myorigin));
|
||||
len = strlen(myorigin);
|
||||
isc_buffer_init(&source, myorigin, len);
|
||||
isc_buffer_add(&source, len);
|
||||
isc_buffer_setactive(&source, len);
|
||||
isc_buffer_init(&target, namebuf, BUFLEN);
|
||||
dns_name_init(&dnsorigin);
|
||||
result = dns_name_fromtext(&dnsorigin, &source, dns_rootname, 0,
|
||||
&target);
|
||||
result = setup_master(nullmsg, nullmsg);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_create(mctx, ZONEDB_DEFAULT, &dnsorigin,
|
||||
result = dns_db_create(mctx, ZONEDB_DEFAULT, dns_origin,
|
||||
dns_dbtype_zone, dns_rdataclass_in, 0, NULL,
|
||||
&db);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
Reference in New Issue
Block a user