Title: [206617] trunk
Revision
206617
Author
[email protected]
Date
2016-09-29 15:02:04 -0700 (Thu, 29 Sep 2016)

Log Message

Fix syntax violation handling in IPv4 address parsing
https://bugs.webkit.org/show_bug.cgi?id=162756

Reviewed by Tim Horton.

Source/WebCore:

When we are parsing the up to 4 numbers in an IPv4 address, if we find a syntax violation 
(the canonicalized address would be different than the input string) then wait to report
it until we have determined that this is a valid IPv4 address that will be canonicalized.
If it is not a valid IPv4 address, then we will just treat the characters as the host, and
that could be no syntax violation.

Covered by a new API test and existing API tests.

* platform/URLParser.cpp:
(WebCore::URLParser::URLParser):
(WebCore::URLParser::parseIPv4Number):
(WebCore::URLParser::parseIPv4Host):
* platform/URLParser.h:

Tools:

* TestWebKitAPI/Tests/WebCore/URLParser.cpp:
(TestWebKitAPI::TEST_F):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206616 => 206617)


--- trunk/Source/WebCore/ChangeLog	2016-09-29 21:28:45 UTC (rev 206616)
+++ trunk/Source/WebCore/ChangeLog	2016-09-29 22:02:04 UTC (rev 206617)
@@ -1,3 +1,24 @@
+2016-09-29  Alex Christensen  <[email protected]>
+
+        Fix syntax violation handling in IPv4 address parsing
+        https://bugs.webkit.org/show_bug.cgi?id=162756
+
+        Reviewed by Tim Horton.
+
+        When we are parsing the up to 4 numbers in an IPv4 address, if we find a syntax violation 
+        (the canonicalized address would be different than the input string) then wait to report
+        it until we have determined that this is a valid IPv4 address that will be canonicalized.
+        If it is not a valid IPv4 address, then we will just treat the characters as the host, and
+        that could be no syntax violation.
+
+        Covered by a new API test and existing API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::URLParser):
+        (WebCore::URLParser::parseIPv4Number):
+        (WebCore::URLParser::parseIPv4Host):
+        * platform/URLParser.h:
+
 2016-09-29  Chris Dumez  <[email protected]>
 
         Fix post-landing nits after r206561.

Modified: trunk/Source/WebCore/platform/URLParser.cpp (206616 => 206617)


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-09-29 21:28:45 UTC (rev 206616)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-09-29 22:02:04 UTC (rev 206617)
@@ -2027,7 +2027,7 @@
 }
 
 template<typename CharacterType>
-Optional<uint32_t> URLParser::parseIPv4Number(CodePointIterator<CharacterType>& iterator, const CodePointIterator<CharacterType>& iteratorForSyntaxViolationPosition)
+Optional<uint32_t> URLParser::parseIPv4Number(CodePointIterator<CharacterType>& iterator, bool& didSeeSyntaxViolation)
 {
     enum class State : uint8_t {
         UnknownBase,
@@ -2040,7 +2040,6 @@
     Checked<uint32_t, RecordOverflow> value = 0;
     if (!iterator.atEnd() && *iterator == '.')
         return Nullopt;
-    bool didSeeSyntaxViolation = false;
     while (!iterator.atEnd()) {
         if (*iterator == '.') {
             ASSERT(!value.hasOverflowed());
@@ -2095,8 +2094,6 @@
             break;
         }
     }
-    if (didSeeSyntaxViolation)
-        syntaxViolation(iteratorForSyntaxViolationPosition);
     ASSERT(!value.hasOverflowed());
     return value.unsafeGet();
 }
@@ -2115,10 +2112,11 @@
 
     Vector<uint32_t, 4> items;
     items.reserveInitialCapacity(4);
+    bool didSeeSyntaxViolation = false;
     while (!iterator.atEnd()) {
         if (items.size() >= 4)
             return Nullopt;
-        if (auto item = parseIPv4Number(iterator, hostBegin))
+        if (auto item = parseIPv4Number(iterator, didSeeSyntaxViolation))
             items.append(item.value());
         else
             return Nullopt;
@@ -2141,6 +2139,9 @@
     }
     if (items[items.size() - 1] >= pow256(5 - items.size()))
         return Nullopt;
+
+    if (didSeeSyntaxViolation)
+        syntaxViolation(hostBegin);
     for (auto item : items) {
         if (item > 255)
             syntaxViolation(hostBegin);

Modified: trunk/Source/WebCore/platform/URLParser.h (206616 => 206617)


--- trunk/Source/WebCore/platform/URLParser.h	2016-09-29 21:28:45 UTC (rev 206616)
+++ trunk/Source/WebCore/platform/URLParser.h	2016-09-29 22:02:04 UTC (rev 206617)
@@ -99,7 +99,7 @@
     using IPv4Address = uint32_t;
     void serializeIPv4(IPv4Address);
     template<typename CharacterType> Optional<IPv4Address> parseIPv4Host(CodePointIterator<CharacterType>);
-    template<typename CharacterType> Optional<uint32_t> parseIPv4Number(CodePointIterator<CharacterType>&, const CodePointIterator<CharacterType>& iteratorForSyntaxViolationPosition);
+    template<typename CharacterType> Optional<uint32_t> parseIPv4Number(CodePointIterator<CharacterType>&, bool& syntaxViolation);
     using IPv6Address = std::array<uint16_t, 8>;
     template<typename CharacterType> Optional<IPv6Address> parseIPv6Host(CodePointIterator<CharacterType>);
     void serializeIPv6Piece(uint16_t piece);

Modified: trunk/Tools/ChangeLog (206616 => 206617)


--- trunk/Tools/ChangeLog	2016-09-29 21:28:45 UTC (rev 206616)
+++ trunk/Tools/ChangeLog	2016-09-29 22:02:04 UTC (rev 206617)
@@ -1,5 +1,15 @@
 2016-09-29  Alex Christensen  <[email protected]>
 
+        Fix syntax violation handling in IPv4 address parsing
+        https://bugs.webkit.org/show_bug.cgi?id=162756
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
+2016-09-29  Alex Christensen  <[email protected]>
+
         URLParser should correctly parse ports with leading 0's
         https://bugs.webkit.org/show_bug.cgi?id=162752
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (206616 => 206617)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-29 21:28:45 UTC (rev 206616)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-29 22:02:04 UTC (rev 206617)
@@ -773,6 +773,7 @@
     checkRelativeURLDifferences("http://f:010/c", "http://example.org/foo/bar",
         {"http", "", "", "f", 10, "/c", "", "", "http://f:10/c"},
         {"http", "", "", "f", 10, "/c", "", "", "http://f:010/c"});
+    checkURL("http://0.0.0.0x100/", {"http", "", "", "0.0.0.0x100", 0, "/", "", "", "http://0.0.0.0x100/"});
 }
 
 TEST_F(URLParserTest, DefaultPort)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to