diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 17:01:16 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 17:01:16 +0000 |
commit | d95fa1894447a1b5b96c482f4bb0290e9983636b (patch) | |
tree | f3f5c5af88598d5c3ccfcec0dc88d089a7a14a42 /net/base/net_util.cc | |
parent | c0553245c3c5548b52055ff353401fd82a4e0892 (diff) | |
download | chromium_src-d95fa1894447a1b5b96c482f4bb0290e9983636b.zip chromium_src-d95fa1894447a1b5b96c482f4bb0290e9983636b.tar.gz chromium_src-d95fa1894447a1b5b96c482f4bb0290e9983636b.tar.bz2 |
Check in patch for pierre.lafayette, http://codereview.chromium.org/178059/show.
Review URL: http://codereview.chromium.org/194057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r-- | net/base/net_util.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 3b6349f..13e99a5 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -749,6 +749,8 @@ std::wstring FormatViewSourceUrl(const GURL& url, namespace net { +std::set<int> explicitly_allowed_ports; + // Appends the substring |in_component| inside of the URL |spec| to |output|, // and the resulting range will be filled into |out_component|. |unescape_rules| // defines how to clean the URL for human readability. @@ -1041,6 +1043,18 @@ bool IsPortAllowedByFtp(int port) { return IsPortAllowedByDefault(port); } +bool IsPortAllowedByOverride(int port) { + if (explicitly_allowed_ports.empty()) + return false; + + std::set<int>::const_iterator it = + std::find(explicitly_allowed_ports.begin(), + explicitly_allowed_ports.end(), + port); + + return it != explicitly_allowed_ports.end(); +} + int SetNonBlocking(int fd) { #if defined(OS_WIN) unsigned long no_block = 1; @@ -1316,4 +1330,33 @@ GURL SimplifyUrlForRequest(const GURL& url) { return url.ReplaceComponents(replacements); } +// Specifies a comma separated list of port numbers that should be accepted +// despite bans. If the string is invalid no allowed ports are stored. +void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports) { + if (allowed_ports.empty()) + return; + + std::set<int> ports; + size_t last = 0; + size_t size = allowed_ports.size(); + // The comma delimiter. + const std::wstring::value_type kComma = L','; + + // Overflow is still possible for evil user inputs. + for (size_t i = 0; i <= size; ++i) { + // The string should be composed of only digits and commas. + if (i != size && !IsAsciiDigit(allowed_ports[i]) && + (allowed_ports[i] != kComma)) + return; + if (i == size || allowed_ports[i] == kComma) { + size_t length = i - last; + if (length > 0) + ports.insert(StringToInt(WideToASCII( + allowed_ports.substr(last, length)))); + last = i + 1; + } + } + explicitly_allowed_ports = ports; +} + } // namespace net |