diff options
author | ttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-12 23:34:50 +0000 |
---|---|---|
committer | ttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-12 23:34:50 +0000 |
commit | 764a9ef21d2e1f2739e516c62551338427819c53 (patch) | |
tree | 89c0832c236be343083288486046cd3a42921bee /net/dns | |
parent | fddbbcd1b8cbfdeb3556328ee2bc3e8a93f0b8c9 (diff) | |
download | chromium_src-764a9ef21d2e1f2739e516c62551338427819c53.zip chromium_src-764a9ef21d2e1f2739e516c62551338427819c53.tar.gz chromium_src-764a9ef21d2e1f2739e516c62551338427819c53.tar.bz2 |
Fix out-of-bounds array access in HostsParser::Advance.
I wasn't checking for npos after SkipWhitespace, so any hosts file
ending in whitespace would run the parser into the weeds.
BUG=259909
TEST=added a test case to dns_hosts_unittest.cc
Review URL: https://chromiumcodereview.appspot.com/18734004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns')
-rw-r--r-- | net/dns/dns_hosts.cc | 6 | ||||
-rw-r--r-- | net/dns/dns_hosts_unittest.cc | 12 |
2 files changed, 17 insertions, 1 deletions
diff --git a/net/dns/dns_hosts.cc b/net/dns/dns_hosts.cc index e0a40a1..852d35c 100644 --- a/net/dns/dns_hosts.cc +++ b/net/dns/dns_hosts.cc @@ -33,8 +33,12 @@ class HostsParser { bool Advance() { bool next_is_ip = (pos_ == 0); while (pos_ < end_ && pos_ != std::string::npos) { - SkipWhitespace(); switch (text_[pos_]) { + case ' ': + case '\t': + SkipWhitespace(); + break; + case '\r': case '\n': next_is_ip = true; diff --git a/net/dns/dns_hosts_unittest.cc b/net/dns/dns_hosts_unittest.cc index 76d4a72..8053203 100644 --- a/net/dns/dns_hosts_unittest.cc +++ b/net/dns/dns_hosts_unittest.cc @@ -64,6 +64,18 @@ TEST(DnsHostsTest, ParseHosts) { ASSERT_EQ(expected, hosts); } +TEST(DnsHostsTest, HostsParser_Empty) { + DnsHosts hosts; + ParseHosts("", &hosts); + EXPECT_EQ(0u, hosts.size()); +} + +TEST(DnsHostsTest, HostsParser_OnlyWhitespace) { + DnsHosts hosts; + ParseHosts(" ", &hosts); + EXPECT_EQ(0u, hosts.size()); +} + } // namespace } // namespace net |