Bug 1462571 - Check dbus name by dbus_validate_bus_name() before use. r=jhorak, a=RyanVM
authorMartin Stransky <stransky@redhat.com>
Fri, 18 May 2018 12:54:03 +0200
changeset 473450 a46bd94230c78f0fd9ccb048fbd993901934fcd7
parent 473449 e5056e8f46927ecc903ff80d5f08850650c30d09
child 473451 4b2b5c188e2ed608af1cafad23e0bf3cd49b2f62
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak, RyanVM
bugs1462571
milestone61.0
Bug 1462571 - Check dbus name by dbus_validate_bus_name() before use. r=jhorak, a=RyanVM MozReview-Commit-ID: AxQp79oyRlm
toolkit/components/remote/nsDBusRemoteService.cpp
widget/xremoteclient/DBusRemoteClient.cpp
--- a/toolkit/components/remote/nsDBusRemoteService.cpp
+++ b/toolkit/components/remote/nsDBusRemoteService.cpp
@@ -184,16 +184,26 @@ nsDBusRemoteService::Startup(const char*
   profileName.ReplaceChar("+/=", '_');
 
   nsAutoCString busName;
   busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(),
                                                  profileName.get());
   if (busName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
     busName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
 
+  // We don't have a valid busName yet - try to create a default one.
+  if (!dbus_validate_bus_name(busName.get(), nullptr)) {
+    busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(), "default");
+    if (!dbus_validate_bus_name(busName.get(), nullptr)) {
+      // We failed completelly to get a valid bus name - just quit
+      // to prevent crash at dbus_bus_request_name().
+      return NS_ERROR_FAILURE;
+    }
+  }
+
   DBusError err;
   dbus_error_init(&err);
   dbus_bus_request_name(mConnection, busName.get(),
                        DBUS_NAME_FLAG_DO_NOT_QUEUE, &err);
   // The interface is already owned - there is another application/profile
   // instance already running.
   if (dbus_error_is_set(&err)) {
     dbus_error_free(&err);
--- a/widget/xremoteclient/DBusRemoteClient.cpp
+++ b/widget/xremoteclient/DBusRemoteClient.cpp
@@ -131,16 +131,27 @@ DBusRemoteClient::GetRemoteDestinationNa
     NS_ENSURE_SUCCESS(rv, false);
     profileName.ReplaceChar("+/=", '_');
 
     aDestinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram,
                                                             profileName.get());
     if (aDestinationName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
       aDestinationName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
 
+    if (!dbus_validate_bus_name(aDestinationName.get(), nullptr)) {
+      // We don't have a valid busName yet - try to create a default one.
+      aDestinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram,
+                                                             "default");
+      if (!dbus_validate_bus_name(aDestinationName.get(), nullptr)) {
+        // We failed completelly to get a valid bus name - just quit
+        // to prevent crash at dbus_bus_request_name().
+        return false;
+      }
+    }
+
     return true;
   }
 }
 
 nsresult
 DBusRemoteClient::DoSendDBusCommandLine(const char *aProgram, const char *aProfile,
                                         const char* aBuffer, int aLength)
 {
@@ -177,9 +188,8 @@ DBusRemoteClient::DoSendDBusCommandLine(
 
   if (dbus_error_is_set(&err)) {
       dbus_error_free(&err);
       return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
-