Changeset 206231 in webkit


Ignore:
Timestamp:
Sep 21, 2016 1:19:07 PM (8 years ago)
Author:
achristensen@apple.com
Message:

URLParser should fail when parsing invalid relative URLs with no schemes
https://bugs.webkit.org/show_bug.cgi?id=162355

Reviewed by Tim Horton.

Source/WebCore:

Covered by new API tests.

  • platform/URLParser.cpp:

(WebCore::copyASCIIStringUntil):
When copying from a null String, is8Bit dereferences a null pointer. We don't want to do that.
(WebCore::URLParser::parse):
What the spec calls a "null" URL matches !url.isValid(), not url.isNull().
The former reflects whether the parsing succeeded,
the latter whether the contained String (which could be an invalid URL) is null.

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206230 r206231  
     12016-09-21  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should fail when parsing invalid relative URLs with no schemes
     4        https://bugs.webkit.org/show_bug.cgi?id=162355
     5
     6        Reviewed by Tim Horton.
     7
     8        Covered by new API tests.
     9
     10        * platform/URLParser.cpp:
     11        (WebCore::copyASCIIStringUntil):
     12        When copying from a null String, is8Bit dereferences a null pointer.  We don't want to do that.
     13        (WebCore::URLParser::parse):
     14        What the spec calls a "null" URL matches !url.isValid(), not url.isNull().
     15        The former reflects whether the parsing succeeded,
     16        the latter whether the contained String (which could be an invalid URL) is null.
     17
    1182016-09-21  Antti Koivisto  <antti@apple.com>
    219
  • trunk/Source/WebCore/platform/URLParser.cpp

    r206223 r206231  
    706706inline static void copyASCIIStringUntil(Vector<LChar>& destination, const String& string, size_t lengthIf8Bit, size_t lengthIf16Bit)
    707707{
     708    if (string.isNull()) {
     709        ASSERT(!lengthIf8Bit);
     710        ASSERT(!lengthIf16Bit);
     711        return;
     712    }
    708713    ASSERT(destination.isEmpty());
    709714    if (string.is8Bit()) {
     
    10701075        case State::NoScheme:
    10711076            LOG_STATE("NoScheme");
    1072             if (base.isNull() || (base.m_cannotBeABaseURL && *c != '#'))
     1077            if (!base.isValid() || (base.m_cannotBeABaseURL && *c != '#'))
    10731078                return failure(input, length);
    10741079            if (base.m_cannotBeABaseURL && *c == '#') {
     
    12411246                break;
    12421247            case '?':
    1243                 if (!base.isNull() && base.protocolIs("file"))
     1248                if (base.isValid() && base.protocolIs("file"))
    12441249                    copyURLPartsUntil(base, URLPart::PathEnd);
    12451250                m_asciiBuffer.append("///?", 4);
     
    12551260                break;
    12561261            case '#':
    1257                 if (!base.isNull() && base.protocolIs("file"))
     1262                if (base.isValid() && base.protocolIs("file"))
    12581263                    copyURLPartsUntil(base, URLPart::QueryEnd);
    12591264                m_asciiBuffer.append("///#", 4);
     
    12701275                break;
    12711276            default:
    1272                 if (!base.isNull() && base.protocolIs("file") && shouldCopyFileURL<serialized>(c))
     1277                if (base.isValid() && base.protocolIs("file") && shouldCopyFileURL<serialized>(c))
    12731278                    copyURLPartsUntil(base, URLPart::PathAfterLastSlash);
    12741279                else {
     
    13001305                break;
    13011306            }
    1302             if (!base.isNull() && base.protocolIs("file")) {
     1307            if (base.isValid() && base.protocolIs("file")) {
    13031308                // FIXME: This String copy is unnecessary.
    13041309                String basePath = base.path();
     
    14601465    case State::SchemeStart:
    14611466        LOG_FINAL_STATE("SchemeStart");
    1462         if (!m_asciiBuffer.size() && !base.isNull())
     1467        if (!m_asciiBuffer.size() && base.isValid())
    14631468            return base;
    14641469        return failure(input, length);
     
    15451550    case State::File:
    15461551        LOG_FINAL_STATE("File");
    1547         if (!base.isNull() && base.protocolIs("file")) {
     1552        if (base.isValid() && base.protocolIs("file")) {
    15481553            copyURLPartsUntil(base, URLPart::QueryEnd);
    15491554            m_asciiBuffer.append(':');
     
    21042109    }
    21052110   
    2106     ASSERT(!serialized || m_hostHasPercentOrNonASCII);
     2111    ASSERT(!serialized || !m_hostHasPercentOrNonASCII);
    21072112    if (!m_hostHasPercentOrNonASCII) {
    21082113        auto hostIterator = iterator;
  • trunk/Tools/ChangeLog

    r206222 r206231  
     12016-09-21  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should fail when parsing invalid relative URLs with no schemes
     4        https://bugs.webkit.org/show_bug.cgi?id=162355
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112016-09-21  Keith Miller  <keith_miller@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r206220 r206231  
    312312    checkRelativeURL("notspecial:/", "http://host", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
    313313    checkRelativeURL("foo:/", "http://example.org/foo/bar", {"foo", "", "", "", 0, "/", "", "", "foo:/"});
     314    checkRelativeURL("://:0/", "http://webkit.org/", {"http", "", "", "webkit.org", 0, "/://:0/", "", "", "http://webkit.org/://:0/"});
    314315
    315316    // The checking of slashes in SpecialAuthoritySlashes needed to get this to pass contradicts what is in the spec,
     
    711712    shouldFail("~", "about:blank");
    712713    shouldFail("~~~");
     714    shouldFail("://:0/");
     715    shouldFail("://:0/", "");
     716    shouldFail("://:0/", "about:blank");
    713717}
    714718
Note: See TracChangeset for help on using the changeset viewer.