Commit 6f4a6681 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Harden URLPattern ctor failure handling

There are two main ctors for URLPattern
- one takes valid schemes and is used with the Parse() method (which
  handles failure)
- one that takes schemes and a string pattern, and assumes parsing must
  succeed

The latter currently has a NOTREACHED() and an error log. Upgrade this
to a DCHECK, since it should never, ever be hit (especially following
the identifying case for crbug.com/856948).

This should - hopefully - help ensure that no new cases are introduced,
and flush out any other cases that may exist.

Bug: 856948
Change-Id: I1982d10e92c72d1d8ca6da03644072a73a0c7580
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450707Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815870}
parent 4933c9c8
......@@ -160,15 +160,9 @@ URLPattern::URLPattern(int valid_schemes, base::StringPiece pattern)
match_subdomains_(false),
port_("*") {
ParseResult result = Parse(pattern);
if (result != ParseResult::kSuccess) {
const char* error_string = GetParseResultString(result);
// Temporarily add more logging to investigate why this code path is
// reached. For http://crbug.com/856948
LOG(ERROR) << "Invalid pattern was given " << pattern << " result "
<< error_string;
NOTREACHED() << "URLPattern invalid: '" << pattern
<< "'; error: " << error_string;
}
DCHECK_EQ(ParseResult::kSuccess, result)
<< "Parsing unexpectedly failed for pattern: " << pattern << ": "
<< GetParseResultString(result);
}
URLPattern::URLPattern(const URLPattern& other) = default;
......
......@@ -98,6 +98,7 @@ class URLPattern {
// Convenience to construct a URLPattern from a string. If the string is not
// known ahead of time, use Parse() instead, which returns success or failure.
// This method will DCHECK if parsing fails.
URLPattern(int valid_schemes, base::StringPiece pattern);
URLPattern();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment