+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.
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) {
FILE* in = fopen(fname, "r");
char buf[102400];
char* np = buf;
+ buf[0]=0;
if(!in) {
perror("fname");
return;
testpkt(pkt, alloc, out, buf);
/* set for new entry */
np = buf;
+ buf[0]=0;
continue;
}
if(np[0] == ';') /* comment */
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);
--- /dev/null
+; 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
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;
#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;
{
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;