Bug 1551664 [Wayland] Validate app name and check dbus path for remote server, r=heftig
authorMartin Stransky <stransky@redhat.com>
Wed, 15 Jan 2020 11:17:40 +0000
changeset 510336 b58ad41837a6b4cedb4652ea994adf4a2190b416
parent 510335 79bce5e9d341d605c6a0c7cc4547be812cefba4a
child 510337 4222f7b9c86b9bc3722d447ccd3b71dbb3d313f5
push id37020
push userccoroiu@mozilla.com
push dateWed, 15 Jan 2020 21:36:21 +0000
treeherdermozilla-central@c35bb210b8ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheftig
bugs1551664
milestone74.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 1551664 [Wayland] Validate app name and check dbus path for remote server, r=heftig Differential Revision: https://phabricator.services.mozilla.com/D59863
toolkit/components/remote/nsDBusRemoteServer.cpp
--- a/toolkit/components/remote/nsDBusRemoteServer.cpp
+++ b/toolkit/components/remote/nsDBusRemoteServer.cpp
@@ -152,17 +152,19 @@ nsresult nsDBusRemoteServer::Startup(con
   mAppName = aAppName;
   ToLowerCase(mAppName);
 
   // D-Bus names can contain only [a-z][A-Z][0-9]_
   // characters so adjust the profile string properly.
   nsAutoCString profileName;
   nsresult rv = mozilla::Base64Encode(nsAutoCString(aProfileName), profileName);
   NS_ENSURE_SUCCESS(rv, rv);
-  profileName.ReplaceChar("+/=", '_');
+
+  profileName.ReplaceChar("+/=-", '_');
+  mAppName.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);
 
   static auto sDBusValidateBusName = (bool (*)(const char*, DBusError*))dlsym(
@@ -189,16 +191,23 @@ nsresult nsDBusRemoteServer::Startup(con
   // instance already running.
   if (dbus_error_is_set(&err)) {
     dbus_error_free(&err);
     mConnection = nullptr;
     return NS_ERROR_FAILURE;
   }
 
   mPathName = nsPrintfCString("/org/mozilla/%s/Remote", mAppName.get());
+  static auto sDBusValidatePathName = (bool (*)(const char*, DBusError*))dlsym(
+      RTLD_DEFAULT, "dbus_validate_path");
+  if (!sDBusValidatePathName ||
+      !sDBusValidatePathName(mPathName.get(), nullptr)) {
+    mConnection = nullptr;
+    return NS_ERROR_FAILURE;
+  }
   if (!dbus_connection_register_object_path(mConnection, mPathName.get(),
                                             &remoteHandlersTable, this)) {
     mConnection = nullptr;
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }