Loading dom/system/linux/PortalLocationProvider.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -221,8 +221,8 @@ PortalLocationProvider::Startup() { // Call CreateSession of the location portal GVariantBuilder builder; nsAutoCString appName(gAppData->remotingName); appName.ReplaceChar("+/=-", '_'); nsAutoCString appName; gAppData->GetDBusAppName(appName); g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); g_variant_builder_add(&builder, "{sv}", "session_handle_token", g_variant_new_string(appName.get())); Loading toolkit/components/remote/nsDBusRemoteClient.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ #include "nsDBusRemoteClient.h" #include "RemoteUtils.h" #include "mozilla/XREAppData.h" #include "mozilla/Logging.h" #include "mozilla/Base64.h" #include "nsPrintfCString.h" Loading Loading @@ -92,7 +93,8 @@ bool nsDBusRemoteClient::GetRemoteDestinationName(const char* aProgram, nsAutoCString profileName; nsresult rv = mozilla::Base64Encode(nsAutoCString(aProfile), profileName); NS_ENSURE_SUCCESS(rv, false); profileName.ReplaceChar("+/=-", '_'); mozilla::XREAppData::SanitizeNameForDBus(profileName); aDestinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram, profileName.get()); Loading Loading @@ -128,7 +130,7 @@ nsresult nsDBusRemoteClient::DoSendDBusCommandLine(const char* aProgram, LOG("nsDBusRemoteClient::DoSendDBusCommandLine()"); nsAutoCString appName(aProgram); appName.ReplaceChar("+/=-", '_'); mozilla::XREAppData::SanitizeNameForDBus(appName); nsAutoCString destinationName; if (!GetRemoteDestinationName(appName.get(), aProfile, destinationName)) { Loading toolkit/components/remote/nsDBusRemoteServer.cpp +10 −16 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ #include "nsDBusRemoteServer.h" #include "nsCOMPtr.h" #include "mozilla/XREAppData.h" #include "mozilla/Base64.h" #include "nsPrintfCString.h" Loading Loading @@ -35,9 +37,7 @@ static const char* introspect_template = "</node>\n"; DBusHandlerResult nsDBusRemoteServer::Introspect(DBusMessage* msg) { DBusMessage* reply; reply = dbus_message_new_method_return(msg); DBusMessage* reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; nsAutoCString introspect_xml; Loading Loading @@ -135,8 +135,7 @@ nsresult nsDBusRemoteServer::Startup(const char* aAppName, aProfileName[0] == '\0') return NS_ERROR_INVALID_ARG; mConnection = already_AddRefed<DBusConnection>(dbus_bus_get(DBUS_BUS_SESSION, nullptr)); mConnection = dont_AddRef(dbus_bus_get(DBUS_BUS_SESSION, nullptr)); if (!mConnection) { return NS_ERROR_FAILURE; } Loading @@ -144,21 +143,16 @@ nsresult nsDBusRemoteServer::Startup(const char* aAppName, dbus_connection_setup_with_g_main(mConnection, nullptr); mAppName = aAppName; ToLowerCase(mAppName); mozilla::XREAppData::SanitizeNameForDBus(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(aProfileName, strlen(aProfileName), profileName); NS_ENSURE_SUCCESS(rv, rv); MOZ_TRY( mozilla::Base64Encode(aProfileName, strlen(aProfileName), profileName)); profileName.ReplaceChar("+/=-", '_'); mAppName.ReplaceChar("+/=-", '_'); mozilla::XREAppData::SanitizeNameForDBus(profileName); nsAutoCString busName; busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(), profileName.get()); nsPrintfCString busName("org.mozilla.%s.%s", mAppName.get(), profileName.get()); if (busName.Length() > DBUS_MAXIMUM_NAME_LENGTH) busName.Truncate(DBUS_MAXIMUM_NAME_LENGTH); Loading xpcom/build/XREAppData.h +5 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #include "mozilla/UniquePtrExtensions.h" #include "nsCOMPtr.h" #include "nsCRTGlue.h" #include "nsStringFwd.h" #include "nsIFile.h" #if defined(XP_WIN) && defined(MOZ_SANDBOX) Loading Loading @@ -190,6 +191,10 @@ class XREAppData { sandbox::BrokerServices* sandboxBrokerServices = nullptr; mozilla::sandboxing::PermissionsService* sandboxPermissionsService; #endif // Returns a name suitable for DBUS services. static void SanitizeNameForDBus(nsACString&); void GetDBusAppName(nsACString&) const; }; /** Loading xpcom/glue/XREAppData.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,25 @@ XREAppData& XREAppData::operator=(const StaticXREAppData& aOther) { XREAppData& XREAppData::operator=(const XREAppData& aOther) = default; void XREAppData::SanitizeNameForDBus(nsACString& aName) { auto IsValidDBusNameChar = [](char aChar) { return IsAsciiAlpha(aChar) || IsAsciiDigit(aChar) || aChar == '_'; }; // D-Bus names can contain only [a-z][A-Z][0-9]_, so we replace all characters // that aren't in that range with underscores. char* cur = aName.BeginWriting(); char* end = aName.EndWriting(); for (; cur != end; cur++) { if (!IsValidDBusNameChar(*cur)) { *cur = '_'; } } } void XREAppData::GetDBusAppName(nsACString& aName) const { aName.Assign(remotingName); SanitizeNameForDBus(aName); } } // namespace mozilla Loading
dom/system/linux/PortalLocationProvider.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -221,8 +221,8 @@ PortalLocationProvider::Startup() { // Call CreateSession of the location portal GVariantBuilder builder; nsAutoCString appName(gAppData->remotingName); appName.ReplaceChar("+/=-", '_'); nsAutoCString appName; gAppData->GetDBusAppName(appName); g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); g_variant_builder_add(&builder, "{sv}", "session_handle_token", g_variant_new_string(appName.get())); Loading
toolkit/components/remote/nsDBusRemoteClient.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ #include "nsDBusRemoteClient.h" #include "RemoteUtils.h" #include "mozilla/XREAppData.h" #include "mozilla/Logging.h" #include "mozilla/Base64.h" #include "nsPrintfCString.h" Loading Loading @@ -92,7 +93,8 @@ bool nsDBusRemoteClient::GetRemoteDestinationName(const char* aProgram, nsAutoCString profileName; nsresult rv = mozilla::Base64Encode(nsAutoCString(aProfile), profileName); NS_ENSURE_SUCCESS(rv, false); profileName.ReplaceChar("+/=-", '_'); mozilla::XREAppData::SanitizeNameForDBus(profileName); aDestinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram, profileName.get()); Loading Loading @@ -128,7 +130,7 @@ nsresult nsDBusRemoteClient::DoSendDBusCommandLine(const char* aProgram, LOG("nsDBusRemoteClient::DoSendDBusCommandLine()"); nsAutoCString appName(aProgram); appName.ReplaceChar("+/=-", '_'); mozilla::XREAppData::SanitizeNameForDBus(appName); nsAutoCString destinationName; if (!GetRemoteDestinationName(appName.get(), aProfile, destinationName)) { Loading
toolkit/components/remote/nsDBusRemoteServer.cpp +10 −16 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ #include "nsDBusRemoteServer.h" #include "nsCOMPtr.h" #include "mozilla/XREAppData.h" #include "mozilla/Base64.h" #include "nsPrintfCString.h" Loading Loading @@ -35,9 +37,7 @@ static const char* introspect_template = "</node>\n"; DBusHandlerResult nsDBusRemoteServer::Introspect(DBusMessage* msg) { DBusMessage* reply; reply = dbus_message_new_method_return(msg); DBusMessage* reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; nsAutoCString introspect_xml; Loading Loading @@ -135,8 +135,7 @@ nsresult nsDBusRemoteServer::Startup(const char* aAppName, aProfileName[0] == '\0') return NS_ERROR_INVALID_ARG; mConnection = already_AddRefed<DBusConnection>(dbus_bus_get(DBUS_BUS_SESSION, nullptr)); mConnection = dont_AddRef(dbus_bus_get(DBUS_BUS_SESSION, nullptr)); if (!mConnection) { return NS_ERROR_FAILURE; } Loading @@ -144,21 +143,16 @@ nsresult nsDBusRemoteServer::Startup(const char* aAppName, dbus_connection_setup_with_g_main(mConnection, nullptr); mAppName = aAppName; ToLowerCase(mAppName); mozilla::XREAppData::SanitizeNameForDBus(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(aProfileName, strlen(aProfileName), profileName); NS_ENSURE_SUCCESS(rv, rv); MOZ_TRY( mozilla::Base64Encode(aProfileName, strlen(aProfileName), profileName)); profileName.ReplaceChar("+/=-", '_'); mAppName.ReplaceChar("+/=-", '_'); mozilla::XREAppData::SanitizeNameForDBus(profileName); nsAutoCString busName; busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(), profileName.get()); nsPrintfCString busName("org.mozilla.%s.%s", mAppName.get(), profileName.get()); if (busName.Length() > DBUS_MAXIMUM_NAME_LENGTH) busName.Truncate(DBUS_MAXIMUM_NAME_LENGTH); Loading
xpcom/build/XREAppData.h +5 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #include "mozilla/UniquePtrExtensions.h" #include "nsCOMPtr.h" #include "nsCRTGlue.h" #include "nsStringFwd.h" #include "nsIFile.h" #if defined(XP_WIN) && defined(MOZ_SANDBOX) Loading Loading @@ -190,6 +191,10 @@ class XREAppData { sandbox::BrokerServices* sandboxBrokerServices = nullptr; mozilla::sandboxing::PermissionsService* sandboxPermissionsService; #endif // Returns a name suitable for DBUS services. static void SanitizeNameForDBus(nsACString&); void GetDBusAppName(nsACString&) const; }; /** Loading
xpcom/glue/XREAppData.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,25 @@ XREAppData& XREAppData::operator=(const StaticXREAppData& aOther) { XREAppData& XREAppData::operator=(const XREAppData& aOther) = default; void XREAppData::SanitizeNameForDBus(nsACString& aName) { auto IsValidDBusNameChar = [](char aChar) { return IsAsciiAlpha(aChar) || IsAsciiDigit(aChar) || aChar == '_'; }; // D-Bus names can contain only [a-z][A-Z][0-9]_, so we replace all characters // that aren't in that range with underscores. char* cur = aName.BeginWriting(); char* end = aName.EndWriting(); for (; cur != end; cur++) { if (!IsValidDBusNameChar(*cur)) { *cur = '_'; } } } void XREAppData::GetDBusAppName(nsACString& aName) const { aName.Assign(remotingName); SanitizeNameForDBus(aName); } } // namespace mozilla