Changeset 225829 in webkit


Ignore:
Timestamp:
Dec 12, 2017 5:54:26 PM (6 years ago)
Author:
achristensen@apple.com
Message:

Fix possible out-of-bounds read in protocolIsInHTTPFamily
https://bugs.webkit.org/show_bug.cgi?id=180688

Reviewed by Daniel Bates.

Source/WebCore:

It wouldn't read very far out of bounds, and it would just change a bool return value,
but it's still out of bounds. Covered by an API test that ASAN wouldn't like.

  • platform/URL.cpp:

(WebCore::protocolIsInHTTPFamily):
Check bounds before reading a string.

Tools:

  • TestWebKitAPI/Tests/WebCore/URL.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225828 r225829  
     12017-12-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix possible out-of-bounds read in protocolIsInHTTPFamily
     4        https://bugs.webkit.org/show_bug.cgi?id=180688
     5
     6        Reviewed by Daniel Bates.
     7
     8        It wouldn't read very far out of bounds, and it would just change a bool return value,
     9        but it's still out of bounds.  Covered by an API test that ASAN wouldn't like.
     10
     11        * platform/URL.cpp:
     12        (WebCore::protocolIsInHTTPFamily):
     13        Check bounds before reading a string.
     14
    1152017-12-12  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/Source/WebCore/platform/URL.cpp

    r225662 r225829  
    874874bool protocolIsInHTTPFamily(const String& url)
    875875{
     876    auto length = url.length();
    876877    // Do the comparison without making a new string object.
    877     return isASCIIAlphaCaselessEqual(url[0], 'h')
     878    return length >= 5
     879        && isASCIIAlphaCaselessEqual(url[0], 'h')
    878880        && isASCIIAlphaCaselessEqual(url[1], 't')
    879881        && isASCIIAlphaCaselessEqual(url[2], 't')
    880882        && isASCIIAlphaCaselessEqual(url[3], 'p')
    881         && (url[4] == ':' || (isASCIIAlphaCaselessEqual(url[4], 's') && url[5] == ':'));
     883        && (url[4] == ':' || (isASCIIAlphaCaselessEqual(url[4], 's') && length >= 6 && url[5] == ':'));
    882884}
    883885
  • trunk/Tools/ChangeLog

    r225824 r225829  
     12017-12-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix possible out-of-bounds read in protocolIsInHTTPFamily
     4        https://bugs.webkit.org/show_bug.cgi?id=180688
     5
     6        Reviewed by Daniel Bates.
     7
     8        * TestWebKitAPI/Tests/WebCore/URL.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112017-12-12  JF Bastien  <jfbastien@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URL.cpp

    r222093 r225829  
    214214}
    215215
     216TEST_F(URLTest, ProtocolIsInHTTPFamily)
     217{
     218    EXPECT_FALSE(protocolIsInHTTPFamily({}));
     219    EXPECT_FALSE(protocolIsInHTTPFamily(""));
     220    EXPECT_FALSE(protocolIsInHTTPFamily("a"));
     221    EXPECT_FALSE(protocolIsInHTTPFamily("ab"));
     222    EXPECT_FALSE(protocolIsInHTTPFamily("abc"));
     223    EXPECT_FALSE(protocolIsInHTTPFamily("abcd"));
     224    EXPECT_FALSE(protocolIsInHTTPFamily("abcde"));
     225    EXPECT_FALSE(protocolIsInHTTPFamily("abcdef"));
     226    EXPECT_FALSE(protocolIsInHTTPFamily("abcdefg"));
     227    EXPECT_TRUE(protocolIsInHTTPFamily("http:"));
     228    EXPECT_FALSE(protocolIsInHTTPFamily("http"));
     229    EXPECT_TRUE(protocolIsInHTTPFamily("https:"));
     230    EXPECT_FALSE(protocolIsInHTTPFamily("https"));
     231    EXPECT_TRUE(protocolIsInHTTPFamily("https://!@#$%^&*()"));
     232}
     233
    216234} // namespace TestWebKitAPI
Note: See TracChangeset for help on using the changeset viewer.