Title: [258396] releases/WebKitGTK/webkit-2.26/Source/WebKit
Revision
258396
Author
ape...@igalia.com
Date
2020-03-13 07:51:42 -0700 (Fri, 13 Mar 2020)

Log Message

Merge r256703 - [Geoclue] Avoid usage of provider in callbacks after it has been destroyed
https://bugs.webkit.org/show_bug.cgi?id=207420

GeoclueGeolocationProvider was making non-cancelable g_dbus_proxy_call(s) with
bare |this| pointer.

Patch by Pavel Feldman <pavel.feld...@gmail.com> on 2020-02-15
Reviewed by Carlos Garcia Campos.

* UIProcess/geoclue/GeoclueGeolocationProvider.cpp:
(WebKit::GeoclueGeolocationProvider::start):
(WebKit::GeoclueGeolocationProvider::stop):
(WebKit::GeoclueGeolocationProvider::setupManager):
(WebKit::GeoclueGeolocationProvider::createClient):
(WebKit::GeoclueGeolocationProvider::startClient):
(WebKit::GeoclueGeolocationProvider::didFail):
* UIProcess/geoclue/GeoclueGeolocationProvider.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/ChangeLog (258395 => 258396)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/ChangeLog	2020-03-13 14:51:35 UTC (rev 258395)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/ChangeLog	2020-03-13 14:51:42 UTC (rev 258396)
@@ -1,3 +1,22 @@
+2020-02-15  Pavel Feldman  <pavel.feld...@gmail.com>
+
+        [Geoclue] Avoid usage of provider in callbacks after it has been destroyed
+        https://bugs.webkit.org/show_bug.cgi?id=207420
+
+        GeoclueGeolocationProvider was making non-cancelable g_dbus_proxy_call(s) with
+        bare |this| pointer.
+
+        Reviewed by Carlos Garcia Campos.
+
+        * UIProcess/geoclue/GeoclueGeolocationProvider.cpp:
+        (WebKit::GeoclueGeolocationProvider::start):
+        (WebKit::GeoclueGeolocationProvider::stop):
+        (WebKit::GeoclueGeolocationProvider::setupManager):
+        (WebKit::GeoclueGeolocationProvider::createClient):
+        (WebKit::GeoclueGeolocationProvider::startClient):
+        (WebKit::GeoclueGeolocationProvider::didFail):
+        * UIProcess/geoclue/GeoclueGeolocationProvider.h:
+
 2020-02-14  Adrian Perez de Castro  <ape...@igalia.com>
 
         Unreviewed. Update OptionsWPE.cmake and NEWS for the 2.26.4 release

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp (258395 => 258396)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp	2020-03-13 14:51:35 UTC (rev 258395)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp	2020-03-13 14:51:42 UTC (rev 258396)
@@ -52,17 +52,23 @@
 
 void GeoclueGeolocationProvider::start(UpdateNotifyFunction&& updateNotifyFunction)
 {
+    if (m_isRunning)
+        return;
+
     m_destroyManagerLaterTimer.stop();
     m_updateNotifyFunction = WTFMove(updateNotifyFunction);
     m_isRunning = true;
-
+    m_cancellable = adoptGRef(g_cancellable_new());
     if (!m_manager) {
         g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,
-            "org.freedesktop.GeoClue2", "/org/freedesktop/GeoClue2/Manager", "org.freedesktop.GeoClue2.Manager", nullptr,
+            "org.freedesktop.GeoClue2", "/org/freedesktop/GeoClue2/Manager", "org.freedesktop.GeoClue2.Manager", m_cancellable.get(),
             [](GObject*, GAsyncResult* result, gpointer userData) {
-                auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
                 GUniqueOutPtr<GError> error;
                 GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
+                if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                    return;
+
+                auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
                 if (error) {
                     provider.didFail(_("Failed to connect to geolocation service"));
                     return;
@@ -83,6 +89,7 @@
     m_isRunning = false;
     m_updateNotifyFunction = nullptr;
     g_cancellable_cancel(m_cancellable.get());
+    m_cancellable = nullptr;
     stopClient();
     destroyManagerLater();
 }
@@ -121,11 +128,14 @@
         return;
     }
 
-    g_dbus_proxy_call(m_manager.get(), "CreateClient", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr,
+    g_dbus_proxy_call(m_manager.get(), "CreateClient", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable.get(),
         [](GObject* manager, GAsyncResult* result, gpointer userData) {
-            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             GUniqueOutPtr<GError> error;
             GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(manager), result, &error.outPtr()));
+            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                return;
+
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             if (error) {
                 provider.didFail(_("Failed to connect to geolocation service"));
                 return;
@@ -144,11 +154,14 @@
     }
 
     g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,
-        "org.freedesktop.GeoClue2", clientPath, "org.freedesktop.GeoClue2.Client", nullptr,
+        "org.freedesktop.GeoClue2", clientPath, "org.freedesktop.GeoClue2.Client", m_cancellable.get(),
         [](GObject*, GAsyncResult* result, gpointer userData) {
-            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             GUniqueOutPtr<GError> error;
             GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
+            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                return;
+
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             if (error) {
                 provider.didFail(_("Failed to connect to geolocation service"));
                 return;
@@ -190,15 +203,14 @@
 
     g_signal_connect(m_client.get(), "g-signal", G_CALLBACK(clientLocationUpdatedCallback), this);
 
-    m_cancellable = adoptGRef(g_cancellable_new());
     g_dbus_proxy_call(m_client.get(), "Start", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable.get(),
         [](GObject* client, GAsyncResult* result, gpointer userData) {
-            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             GUniqueOutPtr<GError> error;
             GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(client), result, &error.outPtr()));
             if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
                 return;
 
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             if (error) {
                 provider.didFail(_("Failed to determine position from geolocation service"));
                 return;
@@ -212,7 +224,6 @@
         return;
 
     g_signal_handlers_disconnect_matched(m_client.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
-    m_cancellable = nullptr;
     g_dbus_proxy_call(m_client.get(), "Stop", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr);
 }
 
@@ -244,12 +255,12 @@
     g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,
         "org.freedesktop.GeoClue2", locationPath, "org.freedesktop.GeoClue2.Location", m_cancellable.get(),
         [](GObject*, GAsyncResult* result, gpointer userData) {
-            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             GUniqueOutPtr<GError> error;
             GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
             if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
                 return;
 
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
             if (error) {
                 provider.didFail(_("Failed to determine position from geolocation service"));
                 return;
@@ -282,7 +293,8 @@
 
 void GeoclueGeolocationProvider::didFail(CString errorMessage)
 {
-    m_updateNotifyFunction({ }, errorMessage);
+    if (m_updateNotifyFunction)
+        m_updateNotifyFunction({ }, errorMessage);
 }
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to