mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
dns_master.c:
fix 2 infinite while loops. use a pool of 5 buffers for dns_name_fromtext target. add master_test.c:
This commit is contained in:
@@ -9,3 +9,5 @@ task_test
|
|||||||
timer_test
|
timer_test
|
||||||
wire_test
|
wire_test
|
||||||
rdata_test
|
rdata_test
|
||||||
|
master_test
|
||||||
|
rbt_test
|
||||||
|
@@ -23,7 +23,8 @@ TARGETS = lex_test \
|
|||||||
rbt_test \
|
rbt_test \
|
||||||
rdata_test \
|
rdata_test \
|
||||||
rwlock_test \
|
rwlock_test \
|
||||||
wire_test
|
wire_test \
|
||||||
|
master_test
|
||||||
|
|
||||||
@BIND9_MAKE_RULES@
|
@BIND9_MAKE_RULES@
|
||||||
|
|
||||||
@@ -57,5 +58,8 @@ rwlock_test: rwlock_test.o ../../lib/isc/libisc.a ../../lib/dns/libdns.a
|
|||||||
wire_test: wire_test.o ../../lib/isc/libisc.a ../../lib/dns/libdns.a
|
wire_test: wire_test.o ../../lib/isc/libisc.a ../../lib/dns/libdns.a
|
||||||
${CC} -o $@ wire_test.o ${LIBS}
|
${CC} -o $@ wire_test.o ${LIBS}
|
||||||
|
|
||||||
|
master_test: master_test.o ../../lib/isc/libisc.a ../../lib/dns/libdns.a
|
||||||
|
${CC} -o $@ master_test.o ${LIBS}
|
||||||
|
|
||||||
clean distclean::
|
clean distclean::
|
||||||
rm -f ${TARGETS}
|
rm -f ${TARGETS}
|
||||||
|
72
bin/tests/master_test.c
Normal file
72
bin/tests/master_test.c
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <isc/mem.h>
|
||||||
|
#include <isc/buffer.h>
|
||||||
|
#include <isc/error.h>
|
||||||
|
|
||||||
|
#include <dns/master.h>
|
||||||
|
#include <dns/name.h>
|
||||||
|
#include <dns/rdataset.h>
|
||||||
|
#include <dns/result.h>
|
||||||
|
#include <dns/types.h>
|
||||||
|
|
||||||
|
dns_result_t print_dataset(dns_name_t *owner, dns_rdataset_t *dataset);
|
||||||
|
|
||||||
|
isc_mem_t *mctx;
|
||||||
|
|
||||||
|
dns_result_t
|
||||||
|
print_dataset(dns_name_t *owner, dns_rdataset_t *dataset) {
|
||||||
|
char buf[64*1024];
|
||||||
|
isc_buffer_t target;
|
||||||
|
dns_result_t result;
|
||||||
|
|
||||||
|
isc_buffer_init(&target, buf, 64*1024, ISC_BUFFERTYPE_TEXT);
|
||||||
|
result = dns_rdataset_totext(dataset, owner, ISC_FALSE, &target);
|
||||||
|
if (result == DNS_R_SUCCESS)
|
||||||
|
fprintf(stdout, "%.*s\n", (int)target.used,
|
||||||
|
(char*)target.base);
|
||||||
|
else
|
||||||
|
fprintf(stdout, "dns_rdataset_totext: %s\n",
|
||||||
|
dns_result_totext(result));
|
||||||
|
|
||||||
|
return (DNS_R_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[]) {
|
||||||
|
dns_result_t result;
|
||||||
|
dns_name_t origin;
|
||||||
|
isc_buffer_t source;
|
||||||
|
isc_buffer_t target;
|
||||||
|
unsigned char name_buf[255];
|
||||||
|
|
||||||
|
argc = argc;
|
||||||
|
|
||||||
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
||||||
|
|
||||||
|
if (argv[1]) {
|
||||||
|
isc_buffer_init(&source, argv[1], strlen(argv[1]),
|
||||||
|
ISC_BUFFERTYPE_TEXT);
|
||||||
|
isc_buffer_add(&source, strlen(argv[1]));
|
||||||
|
isc_buffer_setactive(&source, strlen(argv[1]));
|
||||||
|
isc_buffer_init(&target, name_buf, 255, ISC_BUFFERTYPE_BINARY);
|
||||||
|
dns_name_init(&origin, NULL);
|
||||||
|
result = dns_name_fromtext(&origin, &source, dns_rootname,
|
||||||
|
ISC_FALSE, &target);
|
||||||
|
if (result != DNS_R_SUCCESS) {
|
||||||
|
fprintf(stdout, "dns_name_fromtext: %s\n",
|
||||||
|
dns_result_totext(result));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
result = dns_load_master(argv[1], &origin, 1,
|
||||||
|
print_dataset, mctx);
|
||||||
|
fprintf(stdout, "dns_load_master: %s\n",
|
||||||
|
dns_result_totext(result));
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
@@ -68,7 +68,14 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
int rdcount_save = 0;
|
int rdcount_save = 0;
|
||||||
int rdata_size = 0;
|
int rdata_size = 0;
|
||||||
unsigned char *target_mem = NULL;
|
unsigned char *target_mem = NULL;
|
||||||
int target_size = 64*1024;
|
int target_size = 128*1024;
|
||||||
|
unsigned char name_buf[5][255];
|
||||||
|
isc_boolean_t name_in_use[5];
|
||||||
|
int glue_in_use = -1;
|
||||||
|
int current_in_use = -1;
|
||||||
|
int new_in_use;
|
||||||
|
isc_buffer_t name;
|
||||||
|
isc_lexspecials_t specials;
|
||||||
|
|
||||||
dns_name_init(¤t_name, NULL);
|
dns_name_init(¤t_name, NULL);
|
||||||
dns_name_init(&glue_name, NULL);
|
dns_name_init(&glue_name, NULL);
|
||||||
@@ -79,9 +86,17 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
if (isc_lex_create(mctx, 256, &lex) != ISC_R_SUCCESS)
|
if (isc_lex_create(mctx, 256, &lex) != ISC_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
memset(specials, 0, sizeof specials);
|
||||||
|
specials['('] = 1;
|
||||||
|
specials[')'] = 1;
|
||||||
|
specials['"'] = 1;
|
||||||
|
isc_lex_setspecials(lex, specials);
|
||||||
|
isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE);
|
||||||
|
|
||||||
if (isc_lex_openfile(lex, master_file) != ISC_R_SUCCESS)
|
if (isc_lex_openfile(lex, master_file) != ISC_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
|
||||||
target_mem = isc_mem_get(mctx, target_size);
|
target_mem = isc_mem_get(mctx, target_size);
|
||||||
if (target_mem == NULL) {
|
if (target_mem == NULL) {
|
||||||
result = DNS_R_NOSPACE;
|
result = DNS_R_NOSPACE;
|
||||||
@@ -90,6 +105,7 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
isc_buffer_init(&target, target_mem, target_size,
|
isc_buffer_init(&target, target_mem, target_size,
|
||||||
ISC_BUFFERTYPE_BINARY);
|
ISC_BUFFERTYPE_BINARY);
|
||||||
target_save = target;
|
target_save = target;
|
||||||
|
memset(name_in_use, 0, 5 * sizeof(isc_boolean_t));
|
||||||
do {
|
do {
|
||||||
options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF |
|
options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF |
|
||||||
ISC_LEXOPT_INITIALWS | ISC_LEXOPT_DNSMULTILINE;
|
ISC_LEXOPT_INITIALWS | ISC_LEXOPT_DNSMULTILINE;
|
||||||
@@ -117,6 +133,12 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
|
|
||||||
/* XXX "$" Support */
|
/* XXX "$" Support */
|
||||||
|
|
||||||
|
for (new_in_use = 0; new_in_use < 5 ; new_in_use++)
|
||||||
|
if (!name_in_use[new_in_use])
|
||||||
|
break;
|
||||||
|
INSIST(new_in_use < 5);
|
||||||
|
isc_buffer_init(&name, &name_buf[new_in_use][0], 255,
|
||||||
|
ISC_BUFFERTYPE_BINARY);
|
||||||
dns_name_init(&new_name, NULL);
|
dns_name_init(&new_name, NULL);
|
||||||
isc_buffer_init(&buffer, token.value.as_region.base,
|
isc_buffer_init(&buffer, token.value.as_region.base,
|
||||||
token.value.as_region.length,
|
token.value.as_region.length,
|
||||||
@@ -124,9 +146,8 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
isc_buffer_add(&buffer, token.value.as_region.length);
|
isc_buffer_add(&buffer, token.value.as_region.length);
|
||||||
isc_buffer_setactive(&buffer,
|
isc_buffer_setactive(&buffer,
|
||||||
token.value.as_region.length);
|
token.value.as_region.length);
|
||||||
/* XXX name memory */
|
|
||||||
result = dns_name_fromtext(&new_name, &buffer,
|
result = dns_name_fromtext(&new_name, &buffer,
|
||||||
origin, ISC_FALSE, &target);
|
origin, ISC_FALSE, &name);
|
||||||
|
|
||||||
if (result != DNS_R_SUCCESS)
|
if (result != DNS_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -139,6 +160,8 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
&glue_name, callback);
|
&glue_name, callback);
|
||||||
if (result != DNS_R_SUCCESS)
|
if (result != DNS_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
if (glue_in_use != -1)
|
||||||
|
name_in_use[glue_in_use] = ISC_FALSE;
|
||||||
dns_name_invalidate(&glue_name);
|
dns_name_invalidate(&glue_name);
|
||||||
in_glue = ISC_FALSE;
|
in_glue = ISC_FALSE;
|
||||||
rdcount = rdcount_save;
|
rdcount = rdcount_save;
|
||||||
@@ -155,6 +178,8 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
rdlcount_save = rdlcount;
|
rdlcount_save = rdlcount;
|
||||||
target_save = target;
|
target_save = target;
|
||||||
glue_name = new_name;
|
glue_name = new_name;
|
||||||
|
glue_in_use = new_in_use;
|
||||||
|
name_in_use[glue_in_use] = ISC_TRUE;
|
||||||
} else {
|
} else {
|
||||||
result = commit(¤t_list,
|
result = commit(¤t_list,
|
||||||
¤t_name,
|
¤t_name,
|
||||||
@@ -163,9 +188,17 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
rdcount = 0;
|
rdcount = 0;
|
||||||
rdlcount = 0;
|
rdlcount = 0;
|
||||||
|
if (current_in_use != -1)
|
||||||
|
name_in_use[current_in_use]
|
||||||
|
= ISC_FALSE;
|
||||||
|
current_in_use = new_in_use;
|
||||||
|
name_in_use[current_in_use] = ISC_TRUE;
|
||||||
current_name = new_name;
|
current_name = new_name;
|
||||||
current_known = ISC_TRUE;
|
current_known = ISC_TRUE;
|
||||||
current_has_delegation = ISC_FALSE;
|
current_has_delegation = ISC_FALSE;
|
||||||
|
isc_buffer_init(&target, target_mem,
|
||||||
|
target_size,
|
||||||
|
ISC_BUFFERTYPE_BINARY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -234,7 +267,7 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
else
|
else
|
||||||
this = ISC_LIST_HEAD(current_list);
|
this = ISC_LIST_HEAD(current_list);
|
||||||
|
|
||||||
while ((this = ISC_LIST_HEAD(current_list)) != NULL) {
|
while (this != NULL) {
|
||||||
if (this->type == type)
|
if (this->type == type)
|
||||||
break;
|
break;
|
||||||
this = ISC_LIST_NEXT(this, link);
|
this = ISC_LIST_NEXT(this, link);
|
||||||
@@ -283,6 +316,21 @@ dns_load_master(char *master_file, dns_name_t *origin,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
ISC_LIST_PREPEND(this->rdata, &rdata[rdcount], link);
|
ISC_LIST_PREPEND(this->rdata, &rdata[rdcount], link);
|
||||||
rdcount++;
|
rdcount++;
|
||||||
|
/* We must have at least 64k as rdlen is 61 bits. */
|
||||||
|
if (target.used > (64*1024)) {
|
||||||
|
result = commit(¤t_list, ¤t_name, callback);
|
||||||
|
if (result != DNS_R_SUCCESS)
|
||||||
|
goto cleanup;
|
||||||
|
result = commit(&glue_list, &glue_name, callback);
|
||||||
|
if (result != DNS_R_SUCCESS)
|
||||||
|
goto cleanup;
|
||||||
|
rdcount = 0;
|
||||||
|
rdlcount = 0;
|
||||||
|
in_glue = ISC_FALSE;
|
||||||
|
current_has_delegation = ISC_FALSE;
|
||||||
|
isc_buffer_init(&target, target_mem, target_size,
|
||||||
|
ISC_BUFFERTYPE_BINARY);
|
||||||
|
}
|
||||||
} while (!done);
|
} while (!done);
|
||||||
result = commit(¤t_list, ¤t_name, callback);
|
result = commit(¤t_list, ¤t_name, callback);
|
||||||
if (result != DNS_R_SUCCESS)
|
if (result != DNS_R_SUCCESS)
|
||||||
@@ -452,6 +500,7 @@ is_glue(rdatalist_head_t *head, dns_name_t *owner) {
|
|||||||
dns_name_fromregion(&name, ®ion);
|
dns_name_fromregion(&name, ®ion);
|
||||||
if (dns_name_compare(&name, owner) == 0)
|
if (dns_name_compare(&name, owner) == 0)
|
||||||
return (ISC_TRUE);
|
return (ISC_TRUE);
|
||||||
|
rdata = ISC_LIST_NEXT(rdata, link);
|
||||||
}
|
}
|
||||||
return (ISC_FALSE);
|
return (ISC_FALSE);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user