FQDN with trailing period should be queried first with larger ndot value (#345)

If a query is performed for dynamodb.us-east-1.amazonaws.com. with ndots=5, it was attempting to search the search domains rather than just attempting the FQDN that was passed it.  This patch now at least attempts the FQDN first.

We may need to determine if we should abort any further searching, however as is probably intended.

Fix by: Jonathan Maye-Hobbs (@wheelpharoah)
pull/94/head^2
Jonathan Maye-Hobbs 4 years ago committed by GitHub
parent 5668ed4e10
commit ba597817a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      ares_getaddrinfo.c
  2. 54
      test/ares-test-mock-ai.cc

@ -754,6 +754,7 @@ static int as_is_first(const struct host_query* hquery)
{
char* p;
int ndots = 0;
char* last_char = &hquery->name[strlen(hquery->name)-1];
for (p = hquery->name; *p; p++)
{
if (*p == '.')
@ -761,5 +762,9 @@ static int as_is_first(const struct host_query* hquery)
ndots++;
}
}
if (*last_char == '.') {
/* prevent ARES_EBADNAME for valid FQDN, where ndots < channel->ndots */
return true;
}
return ndots >= hquery->channel->ndots;
}

@ -278,6 +278,57 @@ TEST_P(MockExtraOptsTestAI, SimpleQuery) {
EXPECT_THAT(result.ai_, IncludesV4Address("2.3.4.5"));
}
class MockExtraOptsNDotsTestAI
: public MockChannelOptsTest,
public ::testing::WithParamInterface< std::pair<int, bool> > {
public:
MockExtraOptsNDotsTestAI(int ndots)
: MockChannelOptsTest(1, GetParam().first, GetParam().second,
FillOptions(&opts_, ndots),
ARES_OPT_SOCK_SNDBUF|ARES_OPT_SOCK_RCVBUF|ARES_OPT_NDOTS) {}
static struct ares_options* FillOptions(struct ares_options * opts, int ndots) {
memset(opts, 0, sizeof(struct ares_options));
// Set a few options that affect socket communications
opts->socket_send_buffer_size = 514;
opts->socket_receive_buffer_size = 514;
opts->ndots = ndots;
return opts;
}
private:
struct ares_options opts_;
};
class MockExtraOptsNDots5TestAI : public MockExtraOptsNDotsTestAI {
public:
MockExtraOptsNDots5TestAI() : MockExtraOptsNDotsTestAI(5) {}
};
TEST_P(MockExtraOptsNDots5TestAI, SimpleQuery) {
ares_set_local_ip4(channel_, 0x7F000001);
byte addr6[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
ares_set_local_ip6(channel_, addr6);
ares_set_local_dev(channel_, "dummy");
DNSPacket rsp;
rsp.set_response().set_aa()
.add_question(new DNSQuestion("dynamodb.us-east-1.amazonaws.com", ns_t_a))
.add_answer(new DNSARR("dynamodb.us-east-1.amazonaws.com", 100, {123, 45, 67, 8}));
ON_CALL(server_, OnRequest("dynamodb.us-east-1.amazonaws.com", ns_t_a))
.WillByDefault(SetReply(&server_, &rsp));
AddrInfoResult result;
struct ares_addrinfo_hints hints = {};
hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "dynamodb.us-east-1.amazonaws.com.", NULL, &hints, AddrInfoCallback, &result);
Process();
EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_SUCCESS, result.status_);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV4Address("123.45.67.8"));
}
class MockFlagsChannelOptsTestAI
: public MockChannelOptsTest,
public ::testing::WithParamInterface< std::pair<int, bool> > {
@ -706,6 +757,9 @@ INSTANTIATE_TEST_CASE_P(AddressFamiliesAI, MockTCPChannelTestAI,
INSTANTIATE_TEST_CASE_P(AddressFamiliesAI, MockExtraOptsTestAI,
::testing::ValuesIn(ares::test::families_modes));
INSTANTIATE_TEST_CASE_P(AddressFamiliesAI, MockExtraOptsNDots5TestAI,
::testing::ValuesIn(ares::test::families_modes));
INSTANTIATE_TEST_CASE_P(AddressFamiliesAI, MockNoCheckRespChannelTestAI,
::testing::ValuesIn(ares::test::families_modes));

Loading…
Cancel
Save