Changeset 258521 in webkit


Ignore:
Timestamp:
Mar 16, 2020 3:04:02 PM (4 years ago)
Author:
Chris Dumez
Message:

Crash under WebCookieCache::clearForHost()
https://bugs.webkit.org/show_bug.cgi?id=209149
<rdar://problem/60453086>

Reviewed by Alex Christensen.

Source/WebKit:

Make sure WebCookieCache::pruneCacheIfNecessary() keeps alive the host String it is passing
to WebCookieCache::clearForHost(). Previously, it was merely deferencing a HashSet iterator
and passing that to clearForHost(). However, clearForHost() would then drop the String from
the HashSet and the host would no longer be valid.

Change covered by new API test.

  • WebProcess/WebPage/WebCookieCache.cpp:

(WebKit::WebCookieCache::pruneCacheIfNecessary):

Tools:

Add API test coverage.

  • TestWebKitAPI/Tests/WebKitCocoa/CookiePrivateBrowsing.mm:

(TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r258518 r258521  
     12020-03-16  Chris Dumez  <cdumez@apple.com>
     2
     3        Crash under WebCookieCache::clearForHost()
     4        https://bugs.webkit.org/show_bug.cgi?id=209149
     5        <rdar://problem/60453086>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Make sure WebCookieCache::pruneCacheIfNecessary() keeps alive the host String it is passing
     10        to WebCookieCache::clearForHost(). Previously, it was merely deferencing a HashSet iterator
     11        and passing that to clearForHost(). However, clearForHost() would then drop the String from
     12        the HashSet and the host would no longer be valid.
     13
     14        Change covered by new API test.
     15
     16        * WebProcess/WebPage/WebCookieCache.cpp:
     17        (WebKit::WebCookieCache::pruneCacheIfNecessary):
     18
    1192020-03-16  Per Arne Vollan  <pvollan@apple.com>
    220
  • trunk/Source/WebKit/WebProcess/WebPage/WebCookieCache.cpp

    r257888 r258521  
    119119    static const unsigned maxCachedHosts = 5;
    120120
    121     while (m_hostsWithInMemoryStorage.size() >= maxCachedHosts)
    122         clearForHost(*m_hostsWithInMemoryStorage.random());
     121    while (m_hostsWithInMemoryStorage.size() >= maxCachedHosts) {
     122        String hostToRemove = *m_hostsWithInMemoryStorage.random();
     123        clearForHost(hostToRemove);
     124    }
    123125}
    124126
  • trunk/Tools/ChangeLog

    r258520 r258521  
     12020-03-16  Chris Dumez  <cdumez@apple.com>
     2
     3        Crash under WebCookieCache::clearForHost()
     4        https://bugs.webkit.org/show_bug.cgi?id=209149
     5        <rdar://problem/60453086>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Add API test coverage.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/CookiePrivateBrowsing.mm:
     12        (TEST):
     13
    1142020-03-16  Keith Rollin  <krollin@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/CookiePrivateBrowsing.mm

    r256820 r258521  
    3434#import <WebKit/WKWebViewConfiguration.h>
    3535#import <wtf/RetainPtr.h>
     36#import <wtf/text/StringConcatenateNumbers.h>
    3637#import <wtf/text/WTFString.h>
    3738
     
    129130    EXPECT_WK_STREQ("foo=bar", cookieString);
    130131}
     132
     133TEST(WebKit, CookieCachePruning)
     134{
     135    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     136    auto view = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     137
     138    for (unsigned i = 0; i < 100; ++i) {
     139        [view synchronouslyLoadHTMLString:@"foo" baseURL:[NSURL URLWithString:makeString("http://foo", i, ".example.com/")]];
     140
     141        __block bool doneEvaluatingJavaScript = false;
     142        [view evaluateJavaScript:@"document.cookie;" completionHandler:^(id _Nullable cookie, NSError * _Nullable error) {
     143            EXPECT_NULL(error);
     144            EXPECT_TRUE([cookie isKindOfClass:[NSString class]]);
     145            EXPECT_WK_STREQ("", (NSString *)cookie);
     146            doneEvaluatingJavaScript = true;
     147        }];
     148        TestWebKitAPI::Util::run(&doneEvaluatingJavaScript);
     149    }
     150}
Note: See TracChangeset for help on using the changeset viewer.