Bug 1420124 - X Remote client: Encode DBus interface strings by base64 to avoid failure/crashes, r?jhorak
DBus strings can contain only [a-z][A-Z][0-9]_ chars. Encode profile name (used as part of interface name) by base64 and adjust it to avoid crashes (
Bug 1418985).
MozReview-Commit-ID: J2SQHYRcWDW
--- a/widget/xremoteclient/DBusRemoteClient.cpp
+++ b/widget/xremoteclient/DBusRemoteClient.cpp
@@ -4,16 +4,17 @@
/* vim:set ts=8 sw=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DBusRemoteClient.h"
#include "RemoteUtils.h"
#include "mozilla/Logging.h"
+#include "mozilla/Base64.h"
#include "nsPrintfCString.h"
using mozilla::LogLevel;
static mozilla::LazyLogModule sRemoteLm("DBusRemoteClient");
DBusRemoteClient::DBusRemoteClient()
{
mConnection = nullptr;
@@ -76,30 +77,39 @@ DBusRemoteClient::SendCommandLine (const
static_cast<uint32_t>(rv)));
return rv;
}
nsresult
DBusRemoteClient::DoSendDBusCommandLine(const char *aProgram, const char *aProfile,
const char* aBuffer, int aLength)
{
- NS_ASSERTION(aProfile && aProfile[0] != '\0', "Missing user profile!");
+ if(!aProfile || aProfile[0] == '\0') {
+ return NS_ERROR_INVALID_ARG;
+ }
+
+ // 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("+/=", '_');
nsAutoCString destinationName;
- destinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram, aProfile);
+ destinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram, profileName.get());
- nsAutoCString objectName;
- objectName = nsPrintfCString("/org/mozilla/%s/Remote", aProgram);
+ nsAutoCString pathName;
+ pathName = nsPrintfCString("/org/mozilla/%s/Remote", aProgram);
nsAutoCString remoteInterfaceName;
remoteInterfaceName = nsPrintfCString("org.mozilla.%s", aProgram);
RefPtr<DBusMessage> msg = already_AddRefed<DBusMessage>(
dbus_message_new_method_call(destinationName.get(),
- objectName.get(), // object to call on
+ pathName.get(), // object to call on
remoteInterfaceName.get(), // interface to call on
"OpenURL")); // method name
if (!msg) {
return NS_ERROR_FAILURE;
}
// append arguments
if (!dbus_message_append_args(msg, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,