Changeset 206554 in webkit


Ignore:
Timestamp:
Sep 28, 2016, 2:53:53 PM (9 years ago)
Author:
achristensen@apple.com
Message:

URLParser should properly handle unexpected periods and overflows in IPv4 addresses
https://bugs.webkit.org/show_bug.cgi?id=162655

Reviewed by Geoffrey Garen.

Source/WebCore:

Covered by new API tests.

  • platform/URLParser.cpp:

(WebCore::URLParser::parseIPv4Number):
(WebCore::URLParser::parseIPv4Host):

  • platform/URLParser.h:

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206551 r206554  
     12016-09-28  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should properly handle unexpected periods and overflows in IPv4 addresses
     4        https://bugs.webkit.org/show_bug.cgi?id=162655
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Covered by new API tests.
     9
     10        * platform/URLParser.cpp:
     11        (WebCore::URLParser::parseIPv4Number):
     12        (WebCore::URLParser::parseIPv4Host):
     13        * platform/URLParser.h:
     14
    1152016-09-28  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Source/WebCore/platform/URLParser.cpp

    r206549 r206554  
    19751975Optional<uint32_t> URLParser::parseIPv4Number(CodePointIterator<CharacterType>& iterator, const CodePointIterator<CharacterType>& iteratorForSyntaxViolationPosition)
    19761976{
    1977     // FIXME: Check for overflow.
    19781977    enum class State : uint8_t {
    19791978        UnknownBase,
     
    19841983    };
    19851984    State state = State::UnknownBase;
    1986     uint32_t value = 0;
     1985    Checked<uint32_t, RecordOverflow> value = 0;
     1986    if (!iterator.atEnd() && *iterator == '.')
     1987        return Nullopt;
     1988    bool didSeeSyntaxViolation = false;
    19871989    while (!iterator.atEnd()) {
    19881990        if (*iterator == '.') {
    19891991            ++iterator;
    1990             return value;
     1992            ASSERT(!value.hasOverflowed());
     1993            return value.unsafeGet();
    19911994        }
    19921995        switch (state) {
     
    20002003            break;
    20012004        case State::OctalOrHex:
    2002             syntaxViolation(iteratorForSyntaxViolationPosition);
     2005            didSeeSyntaxViolation = true;
    20032006            if (*iterator == 'x' || *iterator == 'X') {
    20042007                ++iterator;
     
    20132016            value *= 10;
    20142017            value += *iterator - '0';
     2018            if (UNLIKELY(value.hasOverflowed()))
     2019                return Nullopt;
    20152020            ++iterator;
    20162021            break;
    20172022        case State::Octal:
    2018             ASSERT(m_didSeeSyntaxViolation);
     2023            ASSERT(didSeeSyntaxViolation);
    20192024            if (*iterator < '0' || *iterator > '7')
    20202025                return Nullopt;
    20212026            value *= 8;
    20222027            value += *iterator - '0';
     2028            if (UNLIKELY(value.hasOverflowed()))
     2029                return Nullopt;
    20232030            ++iterator;
    20242031            break;
    20252032        case State::Hex:
    2026             ASSERT(m_didSeeSyntaxViolation);
     2033            ASSERT(didSeeSyntaxViolation);
    20272034            if (!isASCIIHexDigit(*iterator))
    20282035                return Nullopt;
    20292036            value *= 16;
    20302037            value += toASCIIHexValue(*iterator);
     2038            if (UNLIKELY(value.hasOverflowed()))
     2039                return Nullopt;
    20312040            ++iterator;
    20322041            break;
    20332042        }
    20342043    }
    2035     return value;
     2044    if (didSeeSyntaxViolation)
     2045        syntaxViolation(iteratorForSyntaxViolationPosition);
     2046    ASSERT(!value.hasOverflowed());
     2047    return value.unsafeGet();
    20362048}
    20372049
     
    20702082    for (auto item : items) {
    20712083        if (item > 255)
    2072             return Nullopt;
     2084            syntaxViolation(hostBegin);
    20732085    }
    20742086
  • trunk/Tools/ChangeLog

    r206553 r206554  
     12016-09-28  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should properly handle unexpected periods and overflows in IPv4 addresses
     4        https://bugs.webkit.org/show_bug.cgi?id=162655
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112016-09-28  Ryan Haddad  <ryanhaddad@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r206549 r206554  
    245245    checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
    246246    checkURL("http:/a", {"http", "", "", "a", 0, "/", "", "", "http://a/"});
    247     checkURL("http://256/", {"http", "", "", "256", 0, "/", "", "", "http://256/"});
    248     checkURL("http://256./", {"http", "", "", "256.", 0, "/", "", "", "http://256./"});
    249     checkURL("http://123.256/", {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});
     247    checkURL("http://256../", {"http", "", "", "256..", 0, "/", "", "", "http://256../"});
     248    checkURL("http://256..", {"http", "", "", "256..", 0, "/", "", "", "http://256../"});
     249    checkURL("http://127..1/", {"http", "", "", "127..1", 0, "/", "", "", "http://127..1/"});
     250    checkURL("http://127.a.0.1/", {"http", "", "", "127.a.0.1", 0, "/", "", "", "http://127.a.0.1/"});
     251    checkURL("http://127.0.0.1/", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
     252    checkURL("http://12\t7.0.0.1/", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
     253    checkURL("http://127.\t0.0.1/", {"http", "", "", "127.0.0.1", 0, "/", "", "", "http://127.0.0.1/"});
     254    checkURL("http://./", {"http", "", "", ".", 0, "/", "", "", "http://./"});
     255    checkURL("http://.", {"http", "", "", ".", 0, "/", "", "", "http://./"});
    250256    checkURL("http://123\t.256/", {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});
    251257    checkURL("http://123.\t256/", {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});
     
    678684        {"file", "", "", "", 0, "/C:/", "", "foo/bar", "file:///C:/#foo/bar"},
    679685        {"", "", "", "", 0, "", "", "", "//C|#foo/bar"});
     686    checkURLDifferences("http://0xFFFFFfFF/",
     687        {"http", "", "", "255.255.255.255", 0, "/", "", "", "http://255.255.255.255/"},
     688        {"http", "", "", "0xffffffff", 0, "/", "", "", "http://0xffffffff/"});
     689    checkURLDifferences("http://0000000000000000037777777777/",
     690        {"http", "", "", "255.255.255.255", 0, "/", "", "", "http://255.255.255.255/"},
     691        {"http", "", "", "0000000000000000037777777777", 0, "/", "", "", "http://0000000000000000037777777777/"});
     692    checkURLDifferences("http://4294967295/",
     693        {"http", "", "", "255.255.255.255", 0, "/", "", "", "http://255.255.255.255/"},
     694        {"http", "", "", "4294967295", 0, "/", "", "", "http://4294967295/"});
     695    checkURLDifferences("http://256/",
     696        {"http", "", "", "0.0.1.0", 0, "/", "", "", "http://0.0.1.0/"},
     697        {"http", "", "", "256", 0, "/", "", "", "http://256/"});
     698    checkURLDifferences("http://256./",
     699        {"http", "", "", "0.0.1.0", 0, "/", "", "", "http://0.0.1.0/"},
     700        {"http", "", "", "256.", 0, "/", "", "", "http://256./"});
     701    checkURLDifferences("http://123.256/",
     702        {"http", "", "", "123.0.1.0", 0, "/", "", "", "http://123.0.1.0/"},
     703        {"http", "", "", "123.256", 0, "/", "", "", "http://123.256/"});
     704    checkURLDifferences("http://127.%.0.1/",
     705        {"", "", "", "", 0, "", "", "", "http://127.%.0.1/"},
     706        {"http", "", "", "127.%.0.1", 0, "/", "", "", "http://127.%.0.1/"});
    680707}
    681708
Note: See TracChangeset for help on using the changeset viewer.