1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-26 20:01:35 +01:00

Soften DNS parsing rules. Fixes #74.

This commit is contained in:
Matias Fontanini
2015-05-10 12:19:58 -07:00
parent 460e87cb43
commit d1ffecb132
2 changed files with 24 additions and 3 deletions

View File

@@ -328,7 +328,7 @@ const uint8_t* DNS::compose_name(const uint8_t *ptr, char *out_ptr) const {
std::memcpy(&index, ptr, sizeof(uint16_t));
index = Endian::be_to_host(index) & 0x3fff;
// Check that the offset is neither too low or too high
if(index < 0x0c || (&records_data[0] + (index - 0x0c)) >= ptr)
if(index < 0x0c || (&records_data[0] + (index - 0x0c)) >= end)
throw malformed_packet();
// We've probably found the end of the original domain name. Save it.
if(end_ptr == 0)

View File

@@ -12,7 +12,8 @@ using namespace Tins;
class DNSTest : public testing::Test {
public:
static const uint8_t expected_packet[], dns_response1[];
static const uint8_t expected_packet[], dns_response1[],
dns_packet1[];
void test_equals(const DNS &dns1, const DNS &dns2);
void test_equals(const DNS::Query &q1, const DNS::Query &q2);
@@ -27,7 +28,19 @@ const uint8_t DNSTest::expected_packet[] = {
};
const uint8_t DNSTest::dns_response1[] = {
174, 73, 129, 128, 0, 1, 0, 5, 0, 0, 0, 0, 6, 103, 111, 111, 103, 108, 101, 3, 99, 111, 109, 0, 0, 15, 0, 1, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 17, 0, 50, 4, 97, 108, 116, 52, 5, 97, 115, 112, 109, 120, 1, 108, 192, 12, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 9, 0, 40, 4, 97, 108, 116, 51, 192, 47, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 9, 0, 20, 4, 97, 108, 116, 49, 192, 47, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 4, 0, 10, 192, 47, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 9, 0, 30, 4, 97, 108, 116, 50, 192, 47
174, 73, 129, 128, 0, 1, 0, 5, 0, 0, 0, 0, 6, 103, 111, 111, 103, 108,
101, 3, 99, 111, 109, 0, 0, 15, 0, 1, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88,
0, 17, 0, 50, 4, 97, 108, 116, 52, 5, 97, 115, 112, 109, 120, 1, 108,
192, 12, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 9, 0, 40, 4, 97, 108,
116, 51, 192, 47, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 9, 0, 20, 4,
97, 108, 116, 49, 192, 47, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 4,
0, 10, 192, 47, 192, 12, 0, 15, 0, 1, 0, 0, 2, 88, 0, 9, 0, 30, 4, 97,
108, 116, 50, 192, 47
};
const uint8_t DNSTest::dns_packet1[] = {
2, 225, 1, 32, 0, 1, 0, 0, 0, 0, 0, 0, 7, 118, 101, 114, 115, 105,
111, 110, 4, 98, 105, 110, 100, 192, 27, 0, 16, 0, 3
};
@@ -129,6 +142,14 @@ TEST_F(DNSTest, ConstructorFromBuffer2) {
}
}
TEST_F(DNSTest, ConstructorFromBuffer3) {
DNS dns(dns_packet1, sizeof(dns_packet1));
EXPECT_EQ(dns.questions_count(), 1);
DNS::queries_type queries = dns.queries();
ASSERT_EQ(1, queries.size());
EXPECT_EQ("version.bind", queries.front().dname());
}
TEST_F(DNSTest, NoRecords) {
DNS dns;
EXPECT_TRUE(dns.queries().empty());