Bug 1462571 - Check dbus name by dbus_validate_bus_name() before use, r=jhorak

MozReview-Commit-ID: AxQp79oyRlm

--HG--
extra : rebase_source : 2065620e9b6387f7b82459c7590315e9e1591944
This commit is contained in:
Martin Stransky 2018-05-18 12:54:03 +02:00
Родитель 26287d7c31
Коммит a3281d15fd
2 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -189,6 +189,16 @@ nsDBusRemoteService::Startup(const char* aAppName, const char* aProfileName)
if (busName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
busName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
// We don't have a valid busName yet - try to create a default one.
if (!dbus_validate_bus_name(busName.get(), nullptr)) {
busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(), "default");
if (!dbus_validate_bus_name(busName.get(), nullptr)) {
// We failed completelly to get a valid bus name - just quit
// to prevent crash at dbus_bus_request_name().
return NS_ERROR_FAILURE;
}
}
DBusError err;
dbus_error_init(&err);
dbus_bus_request_name(mConnection, busName.get(),

Просмотреть файл

@ -136,6 +136,17 @@ DBusRemoteClient::GetRemoteDestinationName(const char *aProgram,
if (aDestinationName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
aDestinationName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
if (!dbus_validate_bus_name(aDestinationName.get(), nullptr)) {
// We don't have a valid busName yet - try to create a default one.
aDestinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram,
"default");
if (!dbus_validate_bus_name(aDestinationName.get(), nullptr)) {
// We failed completelly to get a valid bus name - just quit
// to prevent crash at dbus_bus_request_name().
return false;
}
}
return true;
}
}
@ -182,4 +193,3 @@ DBusRemoteClient::DoSendDBusCommandLine(const char *aProgram, const char *aProfi
return NS_OK;
}