Changeset 238165 in webkit


Ignore:
Timestamp:
Nov 13, 2018 10:14:58 PM (5 years ago)
Author:
rniwa@webkit.org
Message:

WebKit.GeolocationTransitionToLowAccuracy API crashes when enabling PSON
https://bugs.webkit.org/show_bug.cgi?id=191616

Reviewed by Chris Dumez.

The crash was caused by WKView in autorelease pool invoking stopUpdatingCallback after
GeolocationTransitionToLowAccuracyStateTracker in the stack had been destroyed,
resulting in the use-after-free.

Made the tests more robust by clearing geolocation provider before exiting each test
since we can't really prevent WKView from entering an autorelease pool.

Also made WebKit.GeolocationTransitionToLowAccuracy wait for the success callback
instead of simply the end of the navigation so that the test would continue to work
even if a web content process was created for the second web view (lowAccuracyWebView)

  • TestWebKitAPI/Tests/WebKit/Geolocation.cpp:

(TestWebKitAPI::setupGeolocationProvider): Moved "*" to match the WebKit coding style guideline.
(TestWebKitAPI::clearGeolocationProvider): Added.
(TestWebKitAPI::runJavaScriptAlert): Added.
(TestWebKitAPI::didFinishNavigation): Deleted.

  • TestWebKitAPI/Tests/WebKit/geolocationWatchPosition.html:
Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r238158 r238165  
     12018-11-13  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        WebKit.GeolocationTransitionToLowAccuracy API crashes when enabling PSON
     4        https://bugs.webkit.org/show_bug.cgi?id=191616
     5
     6        Reviewed by Chris Dumez.
     7
     8        The crash was caused by WKView in autorelease pool invoking stopUpdatingCallback after
     9        GeolocationTransitionToLowAccuracyStateTracker in the stack had been destroyed,
     10        resulting in the use-after-free.
     11
     12        Made the tests more robust by clearing geolocation provider before exiting each test
     13        since we can't really prevent WKView from entering an autorelease pool.
     14
     15        Also made WebKit.GeolocationTransitionToLowAccuracy wait for the success callback
     16        instead of simply the end of the navigation so that the test would continue to work
     17        even if a web content process was created for the second web view (lowAccuracyWebView)
     18
     19        * TestWebKitAPI/Tests/WebKit/Geolocation.cpp:
     20        (TestWebKitAPI::setupGeolocationProvider): Moved "*" to match the WebKit coding style guideline.
     21        (TestWebKitAPI::clearGeolocationProvider): Added.
     22        (TestWebKitAPI::runJavaScriptAlert): Added.
     23        (TestWebKitAPI::didFinishNavigation): Deleted.
     24        * TestWebKitAPI/Tests/WebKit/geolocationWatchPosition.html:
     25
    1262018-11-13  Chris Dumez  <cdumez@apple.com>
    227
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/Geolocation.cpp

    r235117 r238165  
    105105}
    106106
    107 void setupGeolocationProvider(WKContextRef context, void *clientInfo)
     107void setupGeolocationProvider(WKContextRef context, void* clientInfo)
    108108{
    109109    WKGeolocationProviderV1 providerCallback;
     
    118118    WKGeolocationManagerSetProvider(WKContextGetGeolocationManager(context), &providerCallback.base);
    119119}
     120   
     121void clearGeolocationProvider(WKContextRef context)
     122{
     123    WKGeolocationManagerSetProvider(WKContextGetGeolocationManager(context), nullptr);
     124}
    120125
    121126void setupView(PlatformWebView& webView)
     
    169174
    170175    Util::run(&stateTracker.finished);
     176    clearGeolocationProvider(context.get());
    171177}
    172178
     
    210216
    211217    Util::run(&stateTracker.finished);
     218    clearGeolocationProvider(context.get());
    212219}
    213220
     
    273280    WKPageLoadURL(lowAccuracyWebView.page(), resetUrl.get());
    274281    Util::run(&stateTracker.finished);
     282
     283    clearGeolocationProvider(context.get());
    275284}
    276285
     
    308317};
    309318
    310 static void didFinishNavigation(WKPageRef page, WKNavigationRef, WKTypeRef userData, const void* clientInfo)
     319static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
    311320{
    312321    *static_cast<bool*>(const_cast<void*>(clientInfo)) = true;
     
    316325{
    317326    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    318     WKContextSetMaximumNumberOfProcesses(context.get(), 1);
    319327
    320328    GeolocationTransitionToLowAccuracyStateTracker stateTracker;
     
    332340    bool finishedSecondStep = false;
    333341
    334     WKPageNavigationClientV0 loaderClient;
    335     memset(&loaderClient, 0, sizeof(loaderClient));
    336 
    337     loaderClient.base.version = 0;
    338     loaderClient.base.clientInfo = &finishedSecondStep;
    339     loaderClient.didFinishNavigation = didFinishNavigation;
    340 
    341     WKPageSetPageNavigationClient(lowAccuracyWebView.page(), &loaderClient.base);
     342    WKPageUIClientV2 uiClient;
     343    memset(&uiClient, 0, sizeof(uiClient));
     344    uiClient.base.version = 2;
     345    uiClient.base.clientInfo = &finishedSecondStep;
     346    uiClient.decidePolicyForGeolocationPermissionRequest = decidePolicyForGeolocationPermissionRequestCallBack;
     347    uiClient.runJavaScriptAlert = runJavaScriptAlert;
     348    WKPageSetPageUIClient(lowAccuracyWebView.page(), &uiClient.base);
    342349
    343350    WKRetainPtr<WKURLRef> lowAccuracyURL(AdoptWK, Util::createURLForResource("geolocationWatchPosition", "html"));
     
    347354    WKRetainPtr<WKURLRef> resetUrl = adoptWK(WKURLCreateWithUTF8CString("about:blank"));
    348355    WKPageLoadURL(highAccuracyWebView.page(), resetUrl.get());
     356
    349357    Util::run(&stateTracker.disabledHighAccuracy);
     358
    350359    WKPageLoadURL(lowAccuracyWebView.page(), resetUrl.get());
    351360    Util::run(&stateTracker.finished);
     361
     362    clearGeolocationProvider(context.get());
    352363}
    353364
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/geolocationWatchPosition.html

    r158689 r238165  
    11<script>
    2 navigator.geolocation.watchPosition(function() { });
     2navigator.geolocation.watchPosition(function() { setTimeout(() => alert("SUCCESS"), 0); }, function() { setTimeout(() => alert("FAIL"), 0); }, {timeout: 100});
    33</script>
Note: See TracChangeset for help on using the changeset viewer.