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

Unified Diff: third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp

Issue 2589273003: CSP: fix bugs in parseHost (+ add unit test) (Closed)
Patch Set: Addressed comments. Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp b/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
index 058f5aaaeff93b743b7214770d2e37e350a9600f..578582d2f2c8dc51e47ac5b7bc90bed7cb29a22b 100644
--- a/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
@@ -433,6 +433,7 @@ bool SourceListDirective::parseScheme(const UChar* begin,
// / "*"
// host-char = ALPHA / DIGIT / "-"
//
+// static
bool SourceListDirective::parseHost(
const UChar* begin,
const UChar* end,
@@ -447,29 +448,34 @@ bool SourceListDirective::parseHost(
const UChar* position = begin;
+ // Parse "*" or [ "*." ].
if (skipExactly<UChar>(position, end, '*')) {
hostWildcard = CSPSource::HasWildcard;
- if (position == end)
+ if (position == end) {
+ // "*"
return true;
+ }
if (!skipExactly<UChar>(position, end, '.'))
return false;
}
-
const UChar* hostBegin = position;
+ // Parse 1*host-hcar.
+ if (!skipExactly<UChar, isHostCharacter>(position, end))
+ return false;
+ skipWhile<UChar, isHostCharacter>(position, end);
+
+ // Parse *( "." 1*host-char ).
while (position < end) {
+ if (!skipExactly<UChar>(position, end, '.'))
+ return false;
if (!skipExactly<UChar, isHostCharacter>(position, end))
return false;
-
skipWhile<UChar, isHostCharacter>(position, end);
-
- if (position < end && !skipExactly<UChar>(position, end, '.'))
- return false;
}
- DCHECK(position == end);
host = String(hostBegin, end - hostBegin);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698