mirror of
https://github.com/NLnetLabs/unbound.git
synced 2024-09-21 14:47:09 +00:00
Tests for compression, and decompression in query section fix.
git-svn-id: file:///svn/unbound/trunk@270 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
0ce78d259f
commit
756cb86964
@ -1,3 +1,8 @@
|
||||
1 May 2007: Wouter
|
||||
- decompress query section, extremely lenient acceptance.
|
||||
But only for answers from other servers, not for plain queries.
|
||||
- compression and decompression test cases.
|
||||
|
||||
27 April 2007: Wouter
|
||||
- removed iov usage, it is not good for dns message encoding.
|
||||
- owner name compression more optimal.
|
||||
|
@ -255,7 +255,9 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
|
||||
|
||||
hex_to_buf(pkt, hex);
|
||||
memmove(&id, ldns_buffer_begin(pkt), sizeof(id));
|
||||
memmove(&flags, ldns_buffer_at(pkt, 2), sizeof(flags));
|
||||
if(ldns_buffer_limit(pkt) < 2)
|
||||
flags = 0;
|
||||
else memmove(&flags, ldns_buffer_at(pkt, 2), sizeof(flags));
|
||||
flags = ntohs(flags);
|
||||
ret = reply_info_parse(pkt, alloc, &qi, &rep);
|
||||
if(ret != 0) {
|
||||
@ -366,6 +368,7 @@ testfromdrillfile(ldns_buffer* pkt, struct alloc_cache* alloc,
|
||||
FILE* in = fopen(fname, "r");
|
||||
char buf[102400];
|
||||
char* np = buf;
|
||||
buf[0]=0;
|
||||
if(!in) {
|
||||
perror("fname");
|
||||
return;
|
||||
@ -378,6 +381,7 @@ testfromdrillfile(ldns_buffer* pkt, struct alloc_cache* alloc,
|
||||
testpkt(pkt, alloc, out, buf);
|
||||
/* set for new entry */
|
||||
np = buf;
|
||||
buf[0]=0;
|
||||
continue;
|
||||
}
|
||||
if(np[0] == ';') /* comment */
|
||||
@ -405,6 +409,7 @@ void msgparse_test()
|
||||
testfromfile(pkt, &alloc, out, "testdata/test_packets.3");
|
||||
/* like from drill -w - */
|
||||
testfromdrillfile(pkt, &alloc, out, "testdata/test_packets.4");
|
||||
testfromdrillfile(pkt, &alloc, out, "testdata/test_packets.5");
|
||||
|
||||
/* cleanup */
|
||||
alloc_clear(&alloc);
|
||||
|
56
testdata/test_packets.5
vendored
Normal file
56
testdata/test_packets.5
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
; Hand made test packets.
|
||||
; By Wouter Wijngaards.
|
||||
; These DNS packets contain interesting compression cases.
|
||||
;
|
||||
;-- next packet --
|
||||
; 0. A valid packet (handmade)
|
||||
; id flags qd an ns ar -- header
|
||||
4242 0000 0001 0001 0000 0000
|
||||
; query: qname example.com. qtype A(1) qclass IN(1)
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001
|
||||
; answer: example.com type class ttl rdatalen 10.x address.
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001 00000101 0004 0a203040
|
||||
|
||||
;-- next packet --
|
||||
; 0b. correct compression from answer to query.
|
||||
4242 0000 0001 0001 0000 0000
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001
|
||||
c00c 0001 0001 00000101 0004 0a203040
|
||||
|
||||
;-- next packet --
|
||||
; 1. Compression from query to answer.
|
||||
4242 0000 0001 0001 0000 0000
|
||||
c012 0001 0001
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001 00000101 0004 0a203040
|
||||
|
||||
;-- next packet --
|
||||
; 2. Compression loop answer 1 to answer 2.
|
||||
4242 0000 0001 0002 0000 0000
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001
|
||||
c02d 0001 0001 00000101 0004 0a203040
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001 00000101 0004 0a203050
|
||||
|
||||
;-- next packet --
|
||||
; 2b. Compression loop answer 2 to answer 1.
|
||||
4242 0000 0001 0002 0000 0000
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001 00000101 0004 0a203050
|
||||
c01d 0001 0001 00000101 0004 0a203040
|
||||
|
||||
;-- next packet --
|
||||
; 3. Compression loop to self (in answer section).
|
||||
4242 0000 0001 0001 0000 0000
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001
|
||||
c01d 0001 0001 00000101 0004 0a203040
|
||||
|
||||
;-- next packet --
|
||||
; 4. bad compression pointer - to header.
|
||||
4242 0000 0001 0001 0000 0000
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001
|
||||
c004 0001 0001 00000101 0004 0a203040
|
||||
|
||||
;-- next packet --
|
||||
; 5. bad compression pointer - exceeds packet.
|
||||
4242 0000 0001 0001 0000 0000
|
||||
07 6578616d706c65 03 636f6d 00 0001 0001
|
||||
c0bb 0001 0001 00000101 0004 0a203040
|
@ -528,7 +528,7 @@ parse_query_section(ldns_buffer* pkt, struct msg_parse* msg)
|
||||
if(ldns_buffer_remaining(pkt) <= 0)
|
||||
return LDNS_RCODE_FORMERR;
|
||||
msg->qname = ldns_buffer_current(pkt);
|
||||
if((msg->qname_len = query_dname_len(pkt)) == 0)
|
||||
if((msg->qname_len = pkt_dname_len(pkt)) == 0)
|
||||
return LDNS_RCODE_FORMERR;
|
||||
if(ldns_buffer_remaining(pkt) < sizeof(uint16_t)*2)
|
||||
return LDNS_RCODE_FORMERR;
|
||||
|
@ -50,24 +50,15 @@
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/data/msgparse.h"
|
||||
|
||||
/** copy and allocate an uncompressed dname. */
|
||||
static uint8_t*
|
||||
copy_uncompr(uint8_t* dname, size_t len)
|
||||
{
|
||||
uint8_t* p = (uint8_t*)malloc(len);
|
||||
if(!p)
|
||||
return 0;
|
||||
memmove(p, dname, len);
|
||||
return p;
|
||||
}
|
||||
|
||||
/** allocate qinfo, return 0 on error. */
|
||||
static int
|
||||
parse_create_qinfo(struct msg_parse* msg, struct query_info* qinf)
|
||||
parse_create_qinfo(ldns_buffer* pkt, struct msg_parse* msg,
|
||||
struct query_info* qinf)
|
||||
{
|
||||
if(msg->qname) {
|
||||
if(!(qinf->qname = copy_uncompr(msg->qname, msg->qname_len)))
|
||||
return 0;
|
||||
qinf->qname = (uint8_t*)malloc(msg->qname_len);
|
||||
if(!qinf->qname) return 0;
|
||||
dname_pkt_copy(pkt, qinf->qname, msg->qname);
|
||||
} else qinf->qname = 0;
|
||||
qinf->qnamesize = msg->qname_len;
|
||||
qinf->qtype = msg->qtype;
|
||||
@ -298,7 +289,7 @@ parse_create_msg(ldns_buffer* pkt, struct msg_parse* msg,
|
||||
{
|
||||
int ret;
|
||||
log_assert(pkt && msg);
|
||||
if(!parse_create_qinfo(msg, qinf))
|
||||
if(!parse_create_qinfo(pkt, msg, qinf))
|
||||
return LDNS_RCODE_SERVFAIL;
|
||||
if(!parse_create_repinfo(msg, rep))
|
||||
return LDNS_RCODE_SERVFAIL;
|
||||
|
Loading…
Reference in New Issue
Block a user