summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authoreroman <eroman@chromium.org>2016-03-24 11:57:49 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-24 19:00:15 +0000
commit55fa65c5ce1c15d8a492d6876b2324fd576a83a4 (patch)
treec368b25dca16b929ff7f314267cd9aee288d6d6f /net
parent950d2d3ba6e0aee4bbae0c67eb6c77feaae55314 (diff)
downloadchromium_src-55fa65c5ce1c15d8a492d6876b2324fd576a83a4.zip
chromium_src-55fa65c5ce1c15d8a492d6876b2324fd576a83a4.tar.gz
chromium_src-55fa65c5ce1c15d8a492d6876b2324fd576a83a4.tar.bz2
Don't allow a leading plus in ports for proxy bypass rules.
For instance will reject the rule "*.org:+443" whereas before it would be accepted. BUG=596523, 596570 Review URL: https://codereview.chromium.org/1831653002 Cr-Commit-Position: refs/heads/master@{#383111}
Diffstat (limited to 'net')
-rw-r--r--net/proxy/proxy_bypass_rules.cc10
-rw-r--r--net/proxy/proxy_bypass_rules_unittest.cc9
2 files changed, 13 insertions, 6 deletions
diff --git a/net/proxy/proxy_bypass_rules.cc b/net/proxy/proxy_bypass_rules.cc
index 64a23c9..eafaa98 100644
--- a/net/proxy/proxy_bypass_rules.cc
+++ b/net/proxy/proxy_bypass_rules.cc
@@ -6,13 +6,13 @@
#include "base/stl_util.h"
#include "base/strings/pattern.h"
-#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "net/base/host_port_pair.h"
#include "net/base/ip_address.h"
+#include "net/base/parse_number.h"
#include "net/base/url_util.h"
namespace net {
@@ -317,13 +317,11 @@ bool ProxyBypassRules::AddRuleFromStringInternal(
// Otherwise assume we have <hostname-pattern>[:port].
std::string::size_type pos_colon = raw.rfind(':');
- host = raw;
port = -1;
if (pos_colon != std::string::npos) {
- if (!base::StringToInt(base::StringPiece(raw.begin() + pos_colon + 1,
- raw.end()),
- &port) ||
- (port < 0 || port > 0xFFFF)) {
+ if (!ParseNonNegativeDecimalInt(
+ base::StringPiece(raw.begin() + pos_colon + 1, raw.end()), &port) ||
+ port > 0xFFFF) {
return false; // Port was invalid.
}
raw = raw.substr(0, pos_colon);
diff --git a/net/proxy/proxy_bypass_rules_unittest.cc b/net/proxy/proxy_bypass_rules_unittest.cc
index c099ad6..84cad71 100644
--- a/net/proxy/proxy_bypass_rules_unittest.cc
+++ b/net/proxy/proxy_bypass_rules_unittest.cc
@@ -97,6 +97,15 @@ TEST(ProxyBypassRulesTest, WildcardAtStart) {
EXPECT_FALSE(rules.Matches(GURL("https://www.google.org.com")));
}
+// Tests a codepath that parses hostnamepattern:port, where "port" is invalid
+// by containing a leading plus.
+TEST(ProxyBypassRulesTest, ParseInvalidPort) {
+ ProxyBypassRules rules;
+ EXPECT_TRUE(rules.AddRuleFromString("*.org:443"));
+ EXPECT_FALSE(rules.AddRuleFromString("*.com:+443"));
+ EXPECT_FALSE(rules.AddRuleFromString("*.com:-443"));
+}
+
TEST(ProxyBypassRulesTest, IPV4Address) {
ProxyBypassRules rules;
rules.ParseFromString("192.168.1.1");