summaryrefslogtreecommitdiffstats
path: root/net/dns
diff options
context:
space:
mode:
authorszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 01:34:09 +0000
committerszym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 01:34:09 +0000
commitf4a6d057fda1a466cef8a6e7112abc2cdf514d41 (patch)
tree96f694fae3dca8682147e1ce8c14b67521254b9d /net/dns
parentaada7935963d717837a5ff7848e1f64a19aa8311 (diff)
downloadchromium_src-f4a6d057fda1a466cef8a6e7112abc2cdf514d41.zip
chromium_src-f4a6d057fda1a466cef8a6e7112abc2cdf514d41.tar.gz
chromium_src-f4a6d057fda1a466cef8a6e7112abc2cdf514d41.tar.bz2
[net/dns] Terminate suffix search at NOERROR response even if it includes no addresses.
BUG=115054 TEST=./net_unittests --gtest_filter=DnsTransactionTest.SuffixSearchStop Review URL: http://codereview.chromium.org/9787001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127870 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns')
-rw-r--r--net/dns/dns_response.cc1
-rw-r--r--net/dns/dns_response_unittest.cc10
-rw-r--r--net/dns/dns_transaction.cc9
-rw-r--r--net/dns/dns_transaction_unittest.cc38
4 files changed, 46 insertions, 12 deletions
diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc
index 9518095..725629b 100644
--- a/net/dns/dns_response.cc
+++ b/net/dns/dns_response.cc
@@ -279,6 +279,7 @@ DnsResponse::Result DnsResponse::ParseToAddressList(
}
}
+ // TODO(szym): Extract TTL for NODATA results. http://crbug.com/115051
if (ip_addresses.empty())
return DNS_NO_ADDRESSES;
diff --git a/net/dns/dns_response_unittest.cc b/net/dns/dns_response_unittest.cc
index 6cbf6a1..1861f10 100644
--- a/net/dns/dns_response_unittest.cc
+++ b/net/dns/dns_response_unittest.cc
@@ -358,7 +358,7 @@ const uint8 kResponseNameMismatchInChain[] = {
0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
// Question: name = 'a', type = A (0x1)
0x01, 'a', 0x00, 0x00, 0x01, 0x00, 0x01,
- // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = "b"
+ // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = 'b'
0x01, 'a', 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x03, 0x01, 'b', 0x00,
// Answer: name = 'b', type = A, TTL = 0xFF, RDATA = 10.10.10.10
@@ -387,7 +387,7 @@ const uint8 kResponseCNAMEAfterAddress[] = {
// Answer: name = 'a', type = A, TTL = 0xFF, RDATA = 10.10.10.10.
0x01, 'a', 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x04, 0x0A, 0x0A, 0x0A, 0x0A,
- // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = "b"
+ // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = 'b'
0x01, 'a', 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x03, 0x01, 'b', 0x00,
};
@@ -397,7 +397,7 @@ const uint8 kResponseTTLMismatch[] = {
0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
// Question: name = 'a', type = A (0x1)
0x01, 'a', 0x00, 0x00, 0x01, 0x00, 0x01,
- // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = "b"
+ // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = 'b'
0x01, 'a', 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x03, 0x01, 'b', 0x00,
// Answer: name = 'b', type = A, TTL = 0xFF, RDATA = 10.10.10.10
@@ -410,10 +410,10 @@ const uint8 kResponseTTLMismatch[] = {
const uint8 kResponseNoAddresses[] = {
// Header: 1 question, 1 answer RR, 1 authority RR
- 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
// Question: name = 'a', type = A (0x1)
0x01, 'a', 0x00, 0x00, 0x01, 0x00, 0x01,
- // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = "b"
+ // Answer: name = 'a', type = CNAME, TTL = 0xFF, RDATA = 'b'
0x01, 'a', 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x03, 0x01, 'b', 0x00,
// Authority section
diff --git a/net/dns/dns_transaction.cc b/net/dns/dns_transaction.cc
index 8a0753f..77d1e59 100644
--- a/net/dns/dns_transaction.cc
+++ b/net/dns/dns_transaction.cc
@@ -219,12 +219,11 @@ class DnsUDPAttempt {
}
if (response_->flags() & dns_protocol::kFlagTC)
return ERR_DNS_SERVER_REQUIRES_TCP;
- if (response_->rcode() != dns_protocol::kRcodeNOERROR &&
- response_->rcode() != dns_protocol::kRcodeNXDOMAIN) {
- return ERR_DNS_SERVER_FAILED;
- }
- if (response_->answer_count() == 0)
+ // TODO(szym): Extract TTL for NXDOMAIN results. http://crbug.com/115051
+ if (response_->rcode() == dns_protocol::kRcodeNXDOMAIN)
return ERR_NAME_NOT_RESOLVED;
+ if (response_->rcode() != dns_protocol::kRcodeNOERROR)
+ return ERR_DNS_SERVER_FAILED;
return OK;
}
diff --git a/net/dns/dns_transaction_unittest.cc b/net/dns/dns_transaction_unittest.cc
index 063c6ea..ded54be 100644
--- a/net/dns/dns_transaction_unittest.cc
+++ b/net/dns/dns_transaction_unittest.cc
@@ -150,8 +150,6 @@ class TransactionHelper {
for (int i = 0; i < expected_answer_count_; ++i) {
EXPECT_TRUE(parser.ReadRecord(&record));
}
- // Technically, there could be additional RRs, but not in our test data.
- EXPECT_TRUE(parser.AtEnd());
} else {
EXPECT_EQ(expected_answer_count_, rv);
EXPECT_EQ(NULL, response);
@@ -678,6 +676,42 @@ TEST_F(DnsTransactionTest, DontAppendToMultiLabelName) {
EXPECT_TRUE(helper2.Run(transaction_factory_.get()));
}
+const uint8 kResponseNoData[] = {
+ 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+ // Question
+ 0x01, 'x', 0x01, 'y', 0x01, 'z', 0x01, 'b', 0x00, 0x00, 0x01, 0x00, 0x01,
+ // Authority section, SOA record, TTL 0x3E6
+ 0x01, 'z', 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x03, 0xE6,
+ // Minimal RDATA, 18 bytes
+ 0x00, 0x12,
+ 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+TEST_F(DnsTransactionTest, SuffixSearchStop) {
+ config_.ndots = 2;
+ config_.search.push_back("a");
+ config_.search.push_back("b");
+ config_.search.push_back("c");
+ ConfigureFactory();
+
+ AddRcode("x.y.z", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
+ AddRcode("x.y.z.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
+ AddResponse("x.y.z.b",
+ dns_protocol::kTypeA,
+ 0 /* id */,
+ reinterpret_cast<const char*>(kResponseNoData),
+ arraysize(kResponseNoData));
+ PrepareSockets();
+
+ TransactionHelper helper0("x.y.z", dns_protocol::kTypeA, 0 /* answers */);
+
+ EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
+}
+
} // namespace
} // namespace net