Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: extensions/common/url_pattern.cc

Issue 441643009: Merge 285492 "Don't allow null bytes in hosts of host permissions." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2062/src/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extensions/common/url_pattern.h ('k') | extensions/common/url_pattern_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/url_pattern.h" 5 #include "extensions/common/url_pattern.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 must_keep_these_arrays_in_sync); 43 must_keep_these_arrays_in_sync);
44 44
45 const char kParseSuccess[] = "Success."; 45 const char kParseSuccess[] = "Success.";
46 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; 46 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator.";
47 const char kParseErrorInvalidScheme[] = "Invalid scheme."; 47 const char kParseErrorInvalidScheme[] = "Invalid scheme.";
48 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; 48 const char kParseErrorWrongSchemeType[] = "Wrong scheme type.";
49 const char kParseErrorEmptyHost[] = "Host can not be empty."; 49 const char kParseErrorEmptyHost[] = "Host can not be empty.";
50 const char kParseErrorInvalidHostWildcard[] = "Invalid host wildcard."; 50 const char kParseErrorInvalidHostWildcard[] = "Invalid host wildcard.";
51 const char kParseErrorEmptyPath[] = "Empty path."; 51 const char kParseErrorEmptyPath[] = "Empty path.";
52 const char kParseErrorInvalidPort[] = "Invalid port."; 52 const char kParseErrorInvalidPort[] = "Invalid port.";
53 const char kParseErrorInvalidHost[] = "Invalid host.";
53 54
54 // Message explaining each URLPattern::ParseResult. 55 // Message explaining each URLPattern::ParseResult.
55 const char* const kParseResultMessages[] = { 56 const char* const kParseResultMessages[] = {
56 kParseSuccess, 57 kParseSuccess,
57 kParseErrorMissingSchemeSeparator, 58 kParseErrorMissingSchemeSeparator,
58 kParseErrorInvalidScheme, 59 kParseErrorInvalidScheme,
59 kParseErrorWrongSchemeType, 60 kParseErrorWrongSchemeType,
60 kParseErrorEmptyHost, 61 kParseErrorEmptyHost,
61 kParseErrorInvalidHostWildcard, 62 kParseErrorInvalidHostWildcard,
62 kParseErrorEmptyPath, 63 kParseErrorEmptyPath,
63 kParseErrorInvalidPort, 64 kParseErrorInvalidPort,
65 kParseErrorInvalidHost,
64 }; 66 };
65 67
66 COMPILE_ASSERT(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages), 68 COMPILE_ASSERT(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages),
67 must_add_message_for_each_parse_result); 69 must_add_message_for_each_parse_result);
68 70
69 const char kPathSeparator[] = "/"; 71 const char kPathSeparator[] = "/";
70 72
71 bool IsStandardScheme(const std::string& scheme) { 73 bool IsStandardScheme(const std::string& scheme) {
72 // "*" gets the same treatment as a standard scheme. 74 // "*" gets the same treatment as a standard scheme.
73 if (scheme == "*") 75 if (scheme == "*")
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return PARSE_ERROR_INVALID_PORT; 248 return PARSE_ERROR_INVALID_PORT;
247 host_ = host_.substr(0, port_pos); 249 host_ = host_.substr(0, port_pos);
248 } 250 }
249 251
250 // No other '*' can occur in the host, though. This isn't necessary, but is 252 // No other '*' can occur in the host, though. This isn't necessary, but is
251 // done as a convenience to developers who might otherwise be confused and 253 // done as a convenience to developers who might otherwise be confused and
252 // think '*' works as a glob in the host. 254 // think '*' works as a glob in the host.
253 if (host_.find('*') != std::string::npos) 255 if (host_.find('*') != std::string::npos)
254 return PARSE_ERROR_INVALID_HOST_WILDCARD; 256 return PARSE_ERROR_INVALID_HOST_WILDCARD;
255 257
258 // Null characters are not allowed in hosts.
259 if (host_.find('\0') != std::string::npos)
260 return PARSE_ERROR_INVALID_HOST;
261
256 return PARSE_SUCCESS; 262 return PARSE_SUCCESS;
257 } 263 }
258 264
259 void URLPattern::SetValidSchemes(int valid_schemes) { 265 void URLPattern::SetValidSchemes(int valid_schemes) {
260 spec_.clear(); 266 spec_.clear();
261 valid_schemes_ = valid_schemes; 267 valid_schemes_ = valid_schemes;
262 } 268 }
263 269
264 void URLPattern::SetHost(const std::string& host) { 270 void URLPattern::SetHost(const std::string& host) {
265 spec_.clear(); 271 spec_.clear();
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 551 }
546 552
547 return result; 553 return result;
548 } 554 }
549 555
550 // static 556 // static
551 const char* URLPattern::GetParseResultString( 557 const char* URLPattern::GetParseResultString(
552 URLPattern::ParseResult parse_result) { 558 URLPattern::ParseResult parse_result) {
553 return kParseResultMessages[parse_result]; 559 return kParseResultMessages[parse_result];
554 } 560 }
OLDNEW
« no previous file with comments | « extensions/common/url_pattern.h ('k') | extensions/common/url_pattern_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698