diff --git a/src/app-layer-dns-udp.c b/src/app-layer-dns-udp.c index a56cfa37c2..84e5c1480c 100644 --- a/src/app-layer-dns-udp.c +++ b/src/app-layer-dns-udp.c @@ -527,9 +527,86 @@ end: return (result); } +/** \test TXT records in answer */ +static int DNSUDPParserTest04 (void) { + int result = 0; + uint8_t buf[] = { + 0xc2,0x2f,0x81,0x80,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x0a,0x41,0x41,0x41, + 0x41,0x41,0x4f,0x31,0x6b,0x51,0x41,0x05,0x3d,0x61,0x75,0x74,0x68,0x03,0x73,0x72, + 0x76,0x06,0x74,0x75,0x6e,0x6e,0x65,0x6c,0x03,0x63,0x6f,0x6d,0x00,0x00,0x10,0x00, + 0x01, + /* answer record start */ + 0xc0,0x0c,0x00,0x10,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x22, + /* txt record starts: */ + 0x20, /* proto = IPPROTO_UDP; + f->alproto = ALPROTO_DNS; + f->alstate = DNSStateAlloc(); + + int r = DNSUDPResponseParse(f, f->alstate, NULL, buf, buflen, NULL); + if (r != 1) + goto end; + + result = 1; +end: + UTHFreeFlow(f); + return (result); +} + +/** \test TXT records in answer, bad txtlen */ +static int DNSUDPParserTest05 (void) { + int result = 0; + uint8_t buf[] = { + 0xc2,0x2f,0x81,0x80,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x0a,0x41,0x41,0x41, + 0x41,0x41,0x4f,0x31,0x6b,0x51,0x41,0x05,0x3d,0x61,0x75,0x74,0x68,0x03,0x73,0x72, + 0x76,0x06,0x74,0x75,0x6e,0x6e,0x65,0x6c,0x03,0x63,0x6f,0x6d,0x00,0x00,0x10,0x00, + 0x01, + /* answer record start */ + 0xc0,0x0c,0x00,0x10,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x22, + /* txt record starts: */ + 0x40, /* proto = IPPROTO_UDP; + f->alproto = ALPROTO_DNS; + f->alstate = DNSStateAlloc(); + + int r = DNSUDPResponseParse(f, f->alstate, NULL, buf, buflen, NULL); + if (r != -1) + goto end; + + result = 1; +end: + UTHFreeFlow(f); + return (result); +} + + void DNSUDPParserRegisterTests(void) { UtRegisterTest("DNSUDPParserTest01", DNSUDPParserTest01, 1); UtRegisterTest("DNSUDPParserTest02", DNSUDPParserTest02, 1); UtRegisterTest("DNSUDPParserTest03", DNSUDPParserTest03, 1); + UtRegisterTest("DNSUDPParserTest04", DNSUDPParserTest04, 1); + UtRegisterTest("DNSUDPParserTest05", DNSUDPParserTest05, 1); } #endif