mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-23 16:20:26 -05:00
Unit test for parser with lots fo content.
git-svn-id: file:///svn/unbound/trunk@247 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
1cb321662d
commit
3507ec2e64
4 changed files with 400063 additions and 13 deletions
|
|
@ -7,6 +7,10 @@
|
||||||
* forgot rrset_count addition.
|
* forgot rrset_count addition.
|
||||||
* did & of ptr on stack for memory position calculation.
|
* did & of ptr on stack for memory position calculation.
|
||||||
* dname_pkt_copy forgot to read next label length.
|
* dname_pkt_copy forgot to read next label length.
|
||||||
|
- test from file and fixes
|
||||||
|
* double frees fixed in error conditions.
|
||||||
|
* types with less than full rdata allowed by parser.
|
||||||
|
Some dynamic update packets seem to use it.
|
||||||
|
|
||||||
16 April 2007: Wouter
|
16 April 2007: Wouter
|
||||||
- following a small change in LDNS, parsing code calculates the
|
- following a small change in LDNS, parsing code calculates the
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,22 @@ test_buffers(ldns_buffer* pkt, ldns_buffer* out)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** check if unbound formerr equals ldns formerr. */
|
||||||
|
static void
|
||||||
|
checkformerr(ldns_buffer* pkt)
|
||||||
|
{
|
||||||
|
ldns_pkt* p;
|
||||||
|
ldns_status status = ldns_buffer2pkt_wire(&p, pkt);
|
||||||
|
if(0) printf("formerr, ldns parse is: %s\n",
|
||||||
|
ldns_get_errorstr_by_id(status));
|
||||||
|
if(status == LDNS_STATUS_OK) {
|
||||||
|
printf("Formerr, but ldns gives packet:\n");
|
||||||
|
ldns_pkt_print(stdout, p);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
unit_assert(status != LDNS_STATUS_OK);
|
||||||
|
}
|
||||||
|
|
||||||
/** test a packet */
|
/** test a packet */
|
||||||
static void
|
static void
|
||||||
testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
|
testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
|
||||||
|
|
@ -208,16 +224,18 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
|
||||||
memmove(&flags, ldns_buffer_at(pkt, 2), sizeof(flags));
|
memmove(&flags, ldns_buffer_at(pkt, 2), sizeof(flags));
|
||||||
ret = reply_info_parse(pkt, alloc, &qi, &rep);
|
ret = reply_info_parse(pkt, alloc, &qi, &rep);
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
printf("exit code %d: %s", ret,
|
if(0) printf("parse code %d: %s\n", ret,
|
||||||
ldns_lookup_by_id(ldns_rcodes, ret)->name);
|
ldns_lookup_by_id(ldns_rcodes, ret)->name);
|
||||||
unit_assert(ret == 0);
|
if(ret == LDNS_RCODE_FORMERR)
|
||||||
}
|
checkformerr(pkt);
|
||||||
sz = reply_info_iov_regen(&qi, rep, id, flags, iov, maxiov,
|
unit_assert(ret != LDNS_RCODE_SERVFAIL);
|
||||||
timenow, region);
|
} else {
|
||||||
unit_assert(sz != 0); /* udp packets should fit in 1024 iov */
|
sz = reply_info_iov_regen(&qi, rep, id, flags, iov, maxiov,
|
||||||
write_iov_buffer(out, iov, sz);
|
timenow, region);
|
||||||
|
unit_assert(sz != 0); /* udp packets should fit in 1024 iov */
|
||||||
test_buffers(pkt, out);
|
write_iov_buffer(out, iov, sz);
|
||||||
|
test_buffers(pkt, out);
|
||||||
|
}
|
||||||
|
|
||||||
query_info_clear(&qi);
|
query_info_clear(&qi);
|
||||||
reply_info_parsedelete(rep, alloc);
|
reply_info_parsedelete(rep, alloc);
|
||||||
|
|
@ -263,6 +281,30 @@ simpletest(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out)
|
||||||
" 64 b9 00 04 c0 3a 80 1e ");
|
" 64 b9 00 04 c0 3a 80 1e ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** simple test of parsing. */
|
||||||
|
static void
|
||||||
|
testfromfile(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
|
||||||
|
const char* fname)
|
||||||
|
{
|
||||||
|
FILE* in = fopen(fname, "r");
|
||||||
|
char buf[102400];
|
||||||
|
int no=0;
|
||||||
|
if(!in) {
|
||||||
|
perror("fname");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while(fgets(buf, sizeof(buf), in)) {
|
||||||
|
if(buf[0] == ';') /* comment */
|
||||||
|
continue;
|
||||||
|
if(strlen(buf) < 10) /* skip pcat line numbers. */
|
||||||
|
continue;
|
||||||
|
if(0) printf("test no %d\n", no);
|
||||||
|
testpkt(pkt, alloc, out, buf);
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
fclose(in);
|
||||||
|
}
|
||||||
|
|
||||||
void msgparse_test()
|
void msgparse_test()
|
||||||
{
|
{
|
||||||
ldns_buffer* pkt = ldns_buffer_new(65553);
|
ldns_buffer* pkt = ldns_buffer_new(65553);
|
||||||
|
|
@ -272,7 +314,9 @@ void msgparse_test()
|
||||||
alloc_init(&super_a, NULL, 0);
|
alloc_init(&super_a, NULL, 0);
|
||||||
alloc_init(&alloc, &super_a, 2);
|
alloc_init(&alloc, &super_a, 2);
|
||||||
|
|
||||||
|
printf("testmsgparse\n");
|
||||||
simpletest(pkt, &alloc, out);
|
simpletest(pkt, &alloc, out);
|
||||||
|
testfromfile(pkt, &alloc, out, "testdata/test_packets.1");
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
alloc_clear(&alloc);
|
alloc_clear(&alloc);
|
||||||
|
|
|
||||||
400000
testdata/test_packets.1
vendored
Normal file
400000
testdata/test_packets.1
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -171,13 +171,13 @@ calc_size(ldns_buffer* pkt, uint16_t type, struct rr_parse* rr)
|
||||||
if(ldns_buffer_remaining(pkt) < pkt_len)
|
if(ldns_buffer_remaining(pkt) < pkt_len)
|
||||||
return 0;
|
return 0;
|
||||||
desc = ldns_rr_descript(type);
|
desc = ldns_rr_descript(type);
|
||||||
if(desc->_dname_count > 0) {
|
if(pkt_len > 0 && desc->_dname_count > 0) {
|
||||||
int count = (int)desc->_dname_count;
|
int count = (int)desc->_dname_count;
|
||||||
int rdf = 0;
|
int rdf = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t oldpos;
|
size_t oldpos;
|
||||||
/* skip first part. */
|
/* skip first part. */
|
||||||
while(count) {
|
while(pkt_len > 0 && count) {
|
||||||
switch(desc->_wireformat[rdf]) {
|
switch(desc->_wireformat[rdf]) {
|
||||||
case LDNS_RDF_TYPE_DNAME:
|
case LDNS_RDF_TYPE_DNAME:
|
||||||
/* decompress every domain name */
|
/* decompress every domain name */
|
||||||
|
|
@ -256,13 +256,13 @@ rdata_copy(ldns_buffer* pkt, struct rrset_parse* pset,
|
||||||
return 0;
|
return 0;
|
||||||
log_assert((size_t)pkt_len+2 <= rr->size);
|
log_assert((size_t)pkt_len+2 <= rr->size);
|
||||||
desc = ldns_rr_descript(ntohs(pset->type));
|
desc = ldns_rr_descript(ntohs(pset->type));
|
||||||
if(desc->_dname_count > 0) {
|
if(pkt_len > 0 && desc->_dname_count > 0) {
|
||||||
int count = (int)desc->_dname_count;
|
int count = (int)desc->_dname_count;
|
||||||
int rdf = 0;
|
int rdf = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t oldpos;
|
size_t oldpos;
|
||||||
/* decompress dnames. */
|
/* decompress dnames. */
|
||||||
while(count) {
|
while(pkt_len > 0 && count) {
|
||||||
switch(desc->_wireformat[rdf]) {
|
switch(desc->_wireformat[rdf]) {
|
||||||
case LDNS_RDF_TYPE_DNAME:
|
case LDNS_RDF_TYPE_DNAME:
|
||||||
oldpos = ldns_buffer_position(pkt);
|
oldpos = ldns_buffer_position(pkt);
|
||||||
|
|
@ -414,6 +414,7 @@ int reply_info_parse(ldns_buffer* pkt, struct alloc_cache* alloc,
|
||||||
struct msg_parse* msg;
|
struct msg_parse* msg;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
qinf->qname = NULL;
|
||||||
*rep = NULL;
|
*rep = NULL;
|
||||||
msg = region_alloc(region, sizeof(*msg));
|
msg = region_alloc(region, sizeof(*msg));
|
||||||
if(!msg)
|
if(!msg)
|
||||||
|
|
@ -433,6 +434,7 @@ int reply_info_parse(ldns_buffer* pkt, struct alloc_cache* alloc,
|
||||||
if((ret = parse_create_msg(pkt, msg, alloc, qinf, rep)) != 0) {
|
if((ret = parse_create_msg(pkt, msg, alloc, qinf, rep)) != 0) {
|
||||||
query_info_clear(qinf);
|
query_info_clear(qinf);
|
||||||
reply_info_parsedelete(*rep, alloc);
|
reply_info_parsedelete(*rep, alloc);
|
||||||
|
*rep = NULL;
|
||||||
region_free_all(region);
|
region_free_all(region);
|
||||||
region_destroy(region);
|
region_destroy(region);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue