Bug 1418770 - Truncate DBus names to DBUS_MAXIMUM_NAME_LENGTH, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Mon, 12 Feb 2018 14:08:22 +0100
changeset 753787 7a9e55b1cd8761779753670883b60f9bfe8ffc53
parent 750475 841512e696b91825d24c6dd1a18d277c5f7d2be4
push id98683
push userstransky@redhat.com
push dateMon, 12 Feb 2018 13:08:45 +0000
reviewersjhorak
bugs1418770
milestone60.0a1
Bug 1418770 - Truncate DBus names to DBUS_MAXIMUM_NAME_LENGTH, r?jhorak MozReview-Commit-ID: 6OpVyCUhPoy
toolkit/components/remote/nsDBusRemoteService.cpp
widget/xremoteclient/DBusRemoteClient.cpp
--- a/toolkit/components/remote/nsDBusRemoteService.cpp
+++ b/toolkit/components/remote/nsDBusRemoteService.cpp
@@ -177,30 +177,35 @@ nsDBusRemoteService::Startup(const char*
   nsAutoCString profileName;
   nsresult rv = mozilla::Base64Encode(nsAutoCString(aProfileName), profileName);
   NS_ENSURE_SUCCESS(rv, rv);
   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);
+
   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);
     mConnection = nullptr;
     return NS_ERROR_FAILURE;
   }
 
   nsAutoCString pathName;
   pathName = nsPrintfCString("/org/mozilla/%s/Remote", mAppName.get());
+  if (pathName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
+    pathName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
   if (!dbus_connection_register_object_path(mConnection, pathName.get(),
                                             &remoteHandlersTable, this)) {
     mConnection = nullptr;
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
--- a/widget/xremoteclient/DBusRemoteClient.cpp
+++ b/widget/xremoteclient/DBusRemoteClient.cpp
@@ -90,22 +90,28 @@ DBusRemoteClient::DoSendDBusCommandLine(
   // characters so adjust the profile string properly.
   nsAutoCString profileName;
   nsresult rv = mozilla::Base64Encode(nsAutoCString(aProfile), profileName);
   NS_ENSURE_SUCCESS(rv, rv);
   profileName.ReplaceChar("+/=", '_');
 
   nsAutoCString destinationName;
   destinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram, profileName.get());
+  if (destinationName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
+    destinationName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
 
   nsAutoCString pathName;
   pathName = nsPrintfCString("/org/mozilla/%s/Remote", aProgram);
+  if (pathName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
+    pathName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
 
   nsAutoCString remoteInterfaceName;
   remoteInterfaceName = nsPrintfCString("org.mozilla.%s", aProgram);
+  if (remoteInterfaceName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
+    remoteInterfaceName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
 
   RefPtr<DBusMessage> msg = already_AddRefed<DBusMessage>(
       dbus_message_new_method_call(destinationName.get(),
                                    pathName.get(), // object to call on
                                    remoteInterfaceName.get(), // interface to call on
                                    "OpenURL")); // method name
   if (!msg) {
     return NS_ERROR_FAILURE;