Title: [247693] trunk/Source/WebKit
Revision
247693
Author
[email protected]
Date
2019-07-22 11:51:31 -0700 (Mon, 22 Jul 2019)

Log Message

Make sure to unref captured lambda variables given to _strictTrustEvaluate in the main thread
https://bugs.webkit.org/show_bug.cgi?id=199948

Reviewed by Alex Christensen.

Use a weak pointer instead of a Ref for the NetworkSession.
Add a null check in processServerTrustEvaluation for extra safety if we decide to remove the data task NetworkSession ref.
Make sure to move the NetworkDataTask ref in the completion handler so that the unrefing is done in the main thread.

* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(processServerTrustEvaluation):
(-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (247692 => 247693)


--- trunk/Source/WebKit/ChangeLog	2019-07-22 18:19:38 UTC (rev 247692)
+++ trunk/Source/WebKit/ChangeLog	2019-07-22 18:51:31 UTC (rev 247693)
@@ -1,3 +1,18 @@
+2019-07-22  Youenn Fablet  <[email protected]>
+
+        Make sure to unref captured lambda variables given to _strictTrustEvaluate in the main thread
+        https://bugs.webkit.org/show_bug.cgi?id=199948
+
+        Reviewed by Alex Christensen.
+
+        Use a weak pointer instead of a Ref for the NetworkSession.
+        Add a null check in processServerTrustEvaluation for extra safety if we decide to remove the data task NetworkSession ref.
+        Make sure to move the NetworkDataTask ref in the completion handler so that the unrefing is done in the main thread.
+
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (processServerTrustEvaluation):
+        (-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):
+
 2019-07-22  Alex Christensen  <[email protected]>
 
         Don't always look for a JSC configuration file after r247685

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm (247692 => 247693)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2019-07-22 18:19:38 UTC (rev 247692)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2019-07-22 18:51:31 UTC (rev 247693)
@@ -550,13 +550,8 @@
     return [NSURLSession respondsToSelector:@selector(_strictTrustEvaluate: queue: completionHandler:)];
 }
 
-static inline void processServerTrustEvaluation(NetworkSessionCocoa *session, NSURLAuthenticationChallenge *challenge, OSStatus trustResult, NetworkDataTaskCocoa::TaskIdentifier taskIdentifier, NetworkDataTaskCocoa* networkDataTask, CompletionHandler<void(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential)>&& completionHandler)
+static inline void processServerTrustEvaluation(NetworkSessionCocoa *session, NSURLAuthenticationChallenge *challenge, NetworkDataTaskCocoa::TaskIdentifier taskIdentifier, NetworkDataTaskCocoa* networkDataTask, CompletionHandler<void(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential)>&& completionHandler)
 {
-    if (trustResult == noErr) {
-        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
-        return;
-    }
-
     session->continueDidReceiveChallenge(challenge, taskIdentifier, networkDataTask, [completionHandler = WTFMove(completionHandler), secTrust = retainPtr(challenge.protectionSpace.serverTrust)] (WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential) mutable {
         // FIXME: UIProcess should send us back non nil credentials but the credential IPC encoder currently only serializes ns credentials for username/password.
         if (disposition == WebKit::AuthenticationChallengeDisposition::UseCredential && !credential.nsCredential()) {
@@ -594,8 +589,14 @@
 #if HAVE(CFNETWORK_NSURLSESSION_STRICTRUSTEVALUATE)
             if (canNSURLSessionTrustEvaluate()) {
                 auto* networkDataTask = [self existingTask:task];
-                auto decisionHandler = makeBlockPtr([_session = _session.copyRef(), completionHandler = makeBlockPtr(completionHandler), taskIdentifier, networkDataTask = RefPtr<NetworkDataTaskCocoa>(networkDataTask)](NSURLAuthenticationChallenge *challenge, OSStatus trustResult) mutable {
-                    processServerTrustEvaluation(_session.get(), challenge, trustResult, taskIdentifier, networkDataTask.get(), WTFMove(completionHandler));
+                auto decisionHandler = makeBlockPtr([_session = makeWeakPtr(_session.get()), completionHandler = makeBlockPtr(completionHandler), taskIdentifier, networkDataTask = RefPtr<NetworkDataTaskCocoa>(networkDataTask)](NSURLAuthenticationChallenge *challenge, OSStatus trustResult) mutable {
+                    auto task = WTFMove(networkDataTask);
+                    auto* session = _session.get();
+                    if (trustResult == noErr || !session) {
+                        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
+                        return;
+                    }
+                    processServerTrustEvaluation(session, challenge, taskIdentifier, task.get(), WTFMove(completionHandler));
                 });
                 [NSURLSession _strictTrustEvaluate:challenge queue:[NSOperationQueue mainQueue].underlyingQueue completionHandler:decisionHandler.get()];
                 return;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to