|
|
|
@ -25,6 +25,25 @@ TEST_F(LibraryTest, ParsePtrReplyOK) { |
|
|
|
|
ares_free_hostent(host); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(LibraryTest, ParsePtrReplyCname) { |
|
|
|
|
byte addrv4[4] = {0x10, 0x20, 0x30, 0x40}; |
|
|
|
|
DNSPacket pkt; |
|
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
|
.add_question(new DNSQuestion("64.48.32.16.in-addr.arpa", ns_t_ptr)) |
|
|
|
|
.add_answer(new DNSCnameRR("64.48.32.16.in-addr.arpa", 50, "64.48.32.8.in-addr.arpa")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.8.in-addr.arpa", 100, "other.com")); |
|
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
|
|
|
|
|
|
|
struct hostent *host = nullptr; |
|
|
|
|
EXPECT_EQ(ARES_SUCCESS, ares_parse_ptr_reply(data.data(), data.size(), |
|
|
|
|
addrv4, sizeof(addrv4), AF_INET, &host)); |
|
|
|
|
ASSERT_NE(nullptr, host); |
|
|
|
|
std::stringstream ss; |
|
|
|
|
ss << HostEnt(host); |
|
|
|
|
EXPECT_EQ("{'other.com' aliases=[other.com] addrs=[16.32.48.64]}", ss.str()); |
|
|
|
|
ares_free_hostent(host); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(LibraryTest, ParseManyPtrReply) { |
|
|
|
|
byte addrv4[4] = {0x10, 0x20, 0x30, 0x40}; |
|
|
|
|
DNSPacket pkt; |
|
|
|
@ -133,6 +152,15 @@ TEST_F(LibraryTest, ParsePtrReplyErrors) { |
|
|
|
|
addrv4, sizeof(addrv4), AF_INET, &host)); |
|
|
|
|
EXPECT_EQ(nullptr, host); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Truncated packets with CNAME.
|
|
|
|
|
pkt.add_answer(new DNSCnameRR("64.48.32.16.in-addr.arpa", 50, "64.48.32.8.in-addr.arpa")); |
|
|
|
|
data = pkt.data(); |
|
|
|
|
for (size_t len = 1; len < data.size(); len++) { |
|
|
|
|
EXPECT_EQ(ARES_EBADRESP, ares_parse_ptr_reply(data.data(), len, |
|
|
|
|
addrv4, sizeof(addrv4), AF_INET, &host)); |
|
|
|
|
EXPECT_EQ(nullptr, host); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(LibraryTest, ParsePtrReplyAllocFail) { |
|
|
|
@ -140,11 +168,20 @@ TEST_F(LibraryTest, ParsePtrReplyAllocFail) { |
|
|
|
|
DNSPacket pkt; |
|
|
|
|
pkt.set_qid(0x1234).set_response().set_aa() |
|
|
|
|
.add_question(new DNSQuestion("64.48.32.16.in-addr.arpa", ns_t_ptr)) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other.com")); |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "main.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other1.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other2.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other3.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other4.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other5.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other6.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other7.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other8.com")) |
|
|
|
|
.add_answer(new DNSPtrRR("64.48.32.16.in-addr.arpa", 100, "other9.com")); |
|
|
|
|
std::vector<byte> data = pkt.data(); |
|
|
|
|
struct hostent *host = nullptr; |
|
|
|
|
|
|
|
|
|
for (int ii = 1; ii <= 9; ii++) { |
|
|
|
|
for (int ii = 1; ii <= 63; ii++) { |
|
|
|
|
ClearFails(); |
|
|
|
|
SetAllocFail(ii); |
|
|
|
|
EXPECT_EQ(ARES_ENOMEM, ares_parse_ptr_reply(data.data(), data.size(), |
|
|
|
|