Bug 1418770 - Truncate DBus names used for remote service to DBUS_MAXIMUM_NAME_LENGTH, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Tue, 13 Feb 2018 13:59:39 +0100
changeset 404716 44ad70613f510dd0f955c8f7a0ec36f2d66d9378
parent 404715 8455df429711e560ff70b4047617b7baafb9dfe4
child 404717 a76c022653b53dfc5866dc0ddcaa5e5fbaa9e8f5
push id33489
push userdluca@mozilla.com
push dateThu, 22 Feb 2018 09:59:00 +0000
treeherdermozilla-central@c1c444858b32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1418770
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -181,16 +181,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)
 {