Bug 1418770 - Truncate DBus names used for remote service to DBUS_MAXIMUM_NAME_LENGTH, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Tue, 13 Feb 2018 13:59:39 +0100
changeset 754416 9a9b8f776e39f31eb4e8446a25f14b2f3f8e0bb5
parent 754414 ce03999766d0424ee721cedb1d1d36aac5a49a53
push id98848
push userstransky@redhat.com
push dateTue, 13 Feb 2018 13:03:34 +0000
reviewersjhorak
bugs1418770
milestone60.0a1
Bug 1418770 - Truncate DBus names used for remote service to DBUS_MAXIMUM_NAME_LENGTH, r?jhorak MozReview-Commit-ID: 3Hrt3Ef87WD
toolkit/components/remote/nsDBusRemoteService.cpp
widget/xremoteclient/DBusRemoteClient.cpp
--- a/toolkit/components/remote/nsDBusRemoteService.cpp
+++ b/toolkit/components/remote/nsDBusRemoteService.cpp
@@ -177,16 +177,19 @@ 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);
--- a/widget/xremoteclient/DBusRemoteClient.cpp
+++ b/widget/xremoteclient/DBusRemoteClient.cpp
@@ -128,16 +128,19 @@ DBusRemoteClient::GetRemoteDestinationNa
     // characters so adjust the profile string properly.
     nsAutoCString profileName;
     nsresult rv = mozilla::Base64Encode(nsAutoCString(aProfile), profileName);
     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);
+
     return true;
   }
 }
 
 nsresult
 DBusRemoteClient::DoSendDBusCommandLine(const char *aProgram, const char *aProfile,
                                         const char* aBuffer, int aLength)
 {