Changeset 247693 in webkit


Ignore:
Timestamp:
Jul 22, 2019 11:51:31 AM (5 years ago)
Author:
youenn@apple.com
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:]):

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r247689 r247693  
     12019-07-22  Youenn Fablet  <youenn@apple.com>
     2
     3        Make sure to unref captured lambda variables given to _strictTrustEvaluate in the main thread
     4        https://bugs.webkit.org/show_bug.cgi?id=199948
     5
     6        Reviewed by Alex Christensen.
     7
     8        Use a weak pointer instead of a Ref for the NetworkSession.
     9        Add a null check in processServerTrustEvaluation for extra safety if we decide to remove the data task NetworkSession ref.
     10        Make sure to move the NetworkDataTask ref in the completion handler so that the unrefing is done in the main thread.
     11
     12        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     13        (processServerTrustEvaluation):
     14        (-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):
     15
    1162019-07-22  Alex Christensen  <achristensen@webkit.org>
    217
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r247567 r247693  
    551551}
    552552
    553 static inline void processServerTrustEvaluation(NetworkSessionCocoa *session, NSURLAuthenticationChallenge *challenge, OSStatus trustResult, NetworkDataTaskCocoa::TaskIdentifier taskIdentifier, NetworkDataTaskCocoa* networkDataTask, CompletionHandler<void(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential)>&& completionHandler)
    554 {
    555     if (trustResult == noErr) {
    556         completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
    557         return;
    558     }
    559 
     553static inline void processServerTrustEvaluation(NetworkSessionCocoa *session, NSURLAuthenticationChallenge *challenge, NetworkDataTaskCocoa::TaskIdentifier taskIdentifier, NetworkDataTaskCocoa* networkDataTask, CompletionHandler<void(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential)>&& completionHandler)
     554{
    560555    session->continueDidReceiveChallenge(challenge, taskIdentifier, networkDataTask, [completionHandler = WTFMove(completionHandler), secTrust = retainPtr(challenge.protectionSpace.serverTrust)] (WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential) mutable {
    561556        // FIXME: UIProcess should send us back non nil credentials but the credential IPC encoder currently only serializes ns credentials for username/password.
     
    595590            if (canNSURLSessionTrustEvaluate()) {
    596591                auto* networkDataTask = [self existingTask:task];
    597                 auto decisionHandler = makeBlockPtr([_session = _session.copyRef(), completionHandler = makeBlockPtr(completionHandler), taskIdentifier, networkDataTask = RefPtr<NetworkDataTaskCocoa>(networkDataTask)](NSURLAuthenticationChallenge *challenge, OSStatus trustResult) mutable {
    598                     processServerTrustEvaluation(_session.get(), challenge, trustResult, taskIdentifier, networkDataTask.get(), WTFMove(completionHandler));
     592                auto decisionHandler = makeBlockPtr([_session = makeWeakPtr(_session.get()), completionHandler = makeBlockPtr(completionHandler), taskIdentifier, networkDataTask = RefPtr<NetworkDataTaskCocoa>(networkDataTask)](NSURLAuthenticationChallenge *challenge, OSStatus trustResult) mutable {
     593                    auto task = WTFMove(networkDataTask);
     594                    auto* session = _session.get();
     595                    if (trustResult == noErr || !session) {
     596                        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
     597                        return;
     598                    }
     599                    processServerTrustEvaluation(session, challenge, taskIdentifier, task.get(), WTFMove(completionHandler));
    599600                });
    600601                [NSURLSession _strictTrustEvaluate:challenge queue:[NSOperationQueue mainQueue].underlyingQueue completionHandler:decisionHandler.get()];
Note: See TracChangeset for help on using the changeset viewer.