Crash under WebCore::deleteCookiesForHostnames()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Sep 2018 17:06:26 +0000 (17:06 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Sep 2018 17:06:26 +0000 (17:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190040
<rdar://problem/38020368>

Reviewed by Alex Christensen.

Update NetworkStorageSession::deleteCookiesForHostnames() to properly deal with the fact
that NSHTTPCookie.domain can return nil.

* platform/network/cocoa/NetworkStorageSessionCocoa.mm:
(WebCore::NetworkStorageSession::deleteCookiesForHostnames):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236556 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm

index 7541a4d..789654e 100644 (file)
@@ -1,3 +1,17 @@
+2018-09-27  Chris Dumez  <cdumez@apple.com>
+
+        Crash under WebCore::deleteCookiesForHostnames()
+        https://bugs.webkit.org/show_bug.cgi?id=190040
+        <rdar://problem/38020368>
+
+        Reviewed by Alex Christensen.
+
+        Update NetworkStorageSession::deleteCookiesForHostnames() to properly deal with the fact
+        that NSHTTPCookie.domain can return nil.
+
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+        (WebCore::NetworkStorageSession::deleteCookiesForHostnames):
+
 2018-09-27  Youenn Fablet  <youenn@apple.com>
 
         Use kCVPixelFormatType_420YpCbCr8Planar for capturing frames
index d8c347c..89485a3 100644 (file)
@@ -508,9 +508,12 @@ void NetworkStorageSession::deleteCookiesForHostnames(const Vector<String>& host
         return;
 
     HashMap<String, Vector<RetainPtr<NSHTTPCookie>>> cookiesByDomain;
-    for (NSHTTPCookie* cookie in cookies) {
-        auto& cookies = cookiesByDomain.add(cookie.domain, Vector<RetainPtr<NSHTTPCookie>>()).iterator->value;
-        cookies.append(cookie);
+    for (NSHTTPCookie *cookie in cookies) {
+        if (!cookie.domain)
+            continue;
+        cookiesByDomain.ensure(cookie.domain, [] {
+            return Vector<RetainPtr<NSHTTPCookie>>();
+        }).iterator->value.append(cookie);
     }
 
     for (const auto& hostname : hostnames) {