зеркало из https://github.com/mozilla/gecko-dev.git
Bug 642469 - Sanitize the environment variables upon startup; r=bsmedberg
This commit is contained in:
Родитель
e278db0f63
Коммит
6dd48e75f1
|
@ -41,8 +41,31 @@
|
|||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include "nsSetDllDirectory.h"
|
||||
|
||||
void
|
||||
SanitizeEnvironmentVariables()
|
||||
{
|
||||
DWORD bufferSize = GetEnvironmentVariableW(L"PATH", NULL, 0);
|
||||
if (bufferSize) {
|
||||
wchar_t* originalPath = new wchar_t[bufferSize];
|
||||
if (bufferSize - 1 == GetEnvironmentVariableW(L"PATH", originalPath, bufferSize)) {
|
||||
bufferSize = ExpandEnvironmentStringsW(originalPath, NULL, 0);
|
||||
if (bufferSize) {
|
||||
wchar_t* newPath = new wchar_t[bufferSize];
|
||||
if (ExpandEnvironmentStringsW(originalPath,
|
||||
newPath,
|
||||
bufferSize)) {
|
||||
SetEnvironmentVariableW(L"PATH", newPath);
|
||||
}
|
||||
delete[] newPath;
|
||||
}
|
||||
}
|
||||
delete[] originalPath;
|
||||
}
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
XPCOM_API(void)
|
||||
|
@ -54,6 +77,10 @@ NS_SetDllDirectory(const WCHAR *aDllDirectory)
|
|||
if (!setDllDirectory) {
|
||||
setDllDirectory = reinterpret_cast<pfnSetDllDirectory>
|
||||
(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDllDirectoryW"));
|
||||
|
||||
// If it's the first time we're running this function, sanitize the
|
||||
// environment variables too.
|
||||
SanitizeEnvironmentVariables();
|
||||
}
|
||||
if (setDllDirectory) {
|
||||
setDllDirectory(aDllDirectory);
|
||||
|
|
Загрузка…
Ссылка в новой задаче