⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243608 in webkit


Ignore:
Timestamp:
Mar 28, 2019, 10:50:18 AM (7 years ago)
Author:
Michael Catanzaro
Message:

[WPE][GTK] webkit_web_resource_get_data_finish can return NULL without setting error
https://bugs.webkit.org/show_bug.cgi?id=186276

Reviewed by Carlos Garcia Campos.

Source/WebKit:

Currently it's possible for webkit_web_resource_get_data_finish() to return NULL without
setting the error parameter. This is illegal because it is an API guarantee (and a GObject
convention) that if an error parameter exists, it should be set whenever a function call
returns NULL. Epiphany correctly dereferences the error in this case without checking if it
is NULL, because it knows it does not have to, and crashes. Fix this. We'll return a byte
array of length 1 containing a NUL character. This isn't great, but there's not really any
better solution without deprecating the API or returning an error code to indicate an empty
resource, and it at least fixes the Epiphany crash.

This does not fix bug #186276, in which this function incorrectly returns no data when it
ought to. But that is a different bug. Now, at least we won't crash when no data is
available.

  • UIProcess/API/glib/WebKitWebResource.cpp:

(resourceDataCallback):

Tools:

  • TestWebKitAPI/Tests/WebKitGLib/TestResources.cpp:

(webViewLoadChanged):
(testWebResourceGetDataError):
(testWebResourceGetDataEmpty):
(beforeAll):
(webViewloadChanged): Deleted.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243606 r243608  
     12019-03-28  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [WPE][GTK] webkit_web_resource_get_data_finish can return NULL without setting error
     4        https://bugs.webkit.org/show_bug.cgi?id=186276
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Currently it's possible for webkit_web_resource_get_data_finish() to return NULL without
     9        setting the error parameter. This is illegal because it is an API guarantee (and a GObject
     10        convention) that if an error parameter exists, it should be set whenever a function call
     11        returns NULL. Epiphany correctly dereferences the error in this case without checking if it
     12        is NULL, because it knows it does not have to, and crashes. Fix this. We'll return a byte
     13        array of length 1 containing a NUL character. This isn't great, but there's not really any
     14        better solution without deprecating the API or returning an error code to indicate an empty
     15        resource, and it at least fixes the Epiphany crash.
     16
     17        This does not fix bug #186276, in which this function incorrectly returns no data when it
     18        ought to. But that is a different bug. Now, at least we won't crash when no data is
     19        available.
     20
     21        * UIProcess/API/glib/WebKitWebResource.cpp:
     22        (resourceDataCallback):
     23
    1242019-03-28  Daniel Bates  <dabates@apple.com>
    225
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebResource.cpp

    r222735 r243608  
    352352    ResourceGetDataAsyncData* data = static_cast<ResourceGetDataAsyncData*>(g_task_get_task_data(task));
    353353    data->webData = wkData;
     354    if (!wkData->bytes())
     355        data->webData = API::Data::create(reinterpret_cast<const unsigned char*>(""), 1);
    354356    g_task_return_boolean(task, TRUE);
    355357}
  • trunk/Tools/ChangeLog

    r243567 r243608  
     12019-03-28  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [WPE][GTK] webkit_web_resource_get_data_finish can return NULL without setting error
     4        https://bugs.webkit.org/show_bug.cgi?id=186276
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        * TestWebKitAPI/Tests/WebKitGLib/TestResources.cpp:
     9        (webViewLoadChanged):
     10        (testWebResourceGetDataError):
     11        (testWebResourceGetDataEmpty):
     12        (beforeAll):
     13        (webViewloadChanged): Deleted.
     14
    1152019-03-27  Andy Estes  <aestes@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestResources.cpp

    r239772 r243608  
    537537}
    538538
    539 static void webViewloadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, GMainLoop* mainLoop)
     539static void webViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, GMainLoop* mainLoop)
    540540{
    541541    if (loadEvent != WEBKIT_LOAD_FINISHED)
    542542        return;
    543     g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(webViewloadChanged), mainLoop);
     543    g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(webViewLoadChanged), mainLoop);
    544544    g_main_loop_quit(mainLoop);
    545545}
     
    550550    GRefPtr<WebKitWebView> webView = WEBKIT_WEB_VIEW(Test::createWebView(test->m_webContext.get()));
    551551    webkit_web_view_load_html(webView.get(), "<html></html>", nullptr);
    552     g_signal_connect(webView.get(), "load-changed", G_CALLBACK(webViewloadChanged), mainLoop.get());
     552    g_signal_connect(webView.get(), "load-changed", G_CALLBACK(webViewLoadChanged), mainLoop.get());
    553553    g_main_loop_run(mainLoop.get());
    554554
     
    564564    }, mainLoop.get());
    565565    webView = nullptr;
     566    g_main_loop_run(mainLoop.get());
     567}
     568
     569static void testWebResourceGetDataEmpty(Test* test, gconstpointer)
     570{
     571    GRefPtr<GMainLoop> mainLoop = adoptGRef(g_main_loop_new(nullptr, FALSE));
     572    GRefPtr<WebKitWebView> webView = WEBKIT_WEB_VIEW(Test::createWebView(test->m_webContext.get()));
     573    webkit_web_view_load_html(webView.get(), "", nullptr);
     574    g_signal_connect(webView.get(), "load-changed", G_CALLBACK(webViewLoadChanged), mainLoop.get());
     575    g_main_loop_run(mainLoop.get());
     576
     577    auto* resource = webkit_web_view_get_main_resource(webView.get());
     578    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(resource));
     579    webkit_web_resource_get_data(resource, nullptr, [](GObject* source, GAsyncResult* result, gpointer userData) {
     580        size_t dataSize;
     581        GUniqueOutPtr<GError> error;
     582        auto* data = webkit_web_resource_get_data_finish(WEBKIT_WEB_RESOURCE(source), result, &dataSize, &error.outPtr());
     583        g_assert_nonnull(data);
     584        g_assert_cmpuint(dataSize, ==, 1);
     585        g_assert_cmpint(data[0], ==, '\0');
     586        g_assert_no_error(error.get());
     587        g_main_loop_quit(static_cast<GMainLoop*>(userData));
     588    }, mainLoop.get());
    566589    g_main_loop_run(mainLoop.get());
    567590}
     
    898921    ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData);
    899922    Test::add("WebKitWebResource", "get-data-error", testWebResourceGetDataError);
     923    Test::add("WebKitWebResource", "get-data-empty", testWebResourceGetDataEmpty);
    900924    SingleResourceLoadTest::add("WebKitWebView", "history-cache", testWebViewResourcesHistoryCache);
    901925    SendRequestTest::add("WebKitWebPage", "send-request", testWebResourceSendRequest);
Note: See TracChangeset for help on using the changeset viewer.