Bug 286382 - Don't load DLLs from the current directory; r=bsmedberg a=blocking-betaN+
--- a/ipc/app/MozillaRuntimeMain.cpp
+++ b/ipc/app/MozillaRuntimeMain.cpp
@@ -53,16 +53,27 @@
int
main(int argc, char* argv[])
{
#if defined(XP_WIN) && defined(DEBUG_bent)
MessageBox(NULL, L"Hi", L"Hi", MB_OK);
#endif
+#ifdef XP_WIN
+ typedef BOOL
+ (WINAPI *pfnSetDllDirectory) (LPCWSTR);
+ pfnSetDllDirectory setDllDirectory =
+ reinterpret_cast<pfnSetDllDirectory>
+ (GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDllDirectoryW"));
+ if (setDllDirectory) {
+ setDllDirectory(L"");
+ }
+#endif
+
// Check for the absolute minimum number of args we need to move
// forward here. We expect the last arg to be the child process type.
if (argc < 1)
return 1;
GeckoProcessType proctype = XRE_StringToChildProcessType(argv[--argc]);
nsresult rv = XRE_InitChildProcess(argc, argv, proctype);
NS_ENSURE_SUCCESS(rv, 1);
--- a/modules/plugin/base/src/nsPluginsDirWin.cpp
+++ b/modules/plugin/base/src/nsPluginsDirWin.cpp
@@ -282,20 +282,33 @@ nsresult nsPluginFile::LoadPlugin(PRLibr
NS_ASSERTION(dwCheck <= MAX_PATH + 1, "Error in Loading plugin");
if (dwCheck <= MAX_PATH + 1) {
restoreOrigDir = SetCurrentDirectoryW(pluginFolderPath.get());
NS_ASSERTION(restoreOrigDir, "Error in Loading plugin");
}
#endif
+ typedef BOOL
+ (WINAPI *pfnSetDllDirectory) (LPCWSTR);
+ pfnSetDllDirectory setDllDirectory =
+ reinterpret_cast<pfnSetDllDirectory>
+ (GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDllDirectoryW"));
+ if (setDllDirectory) {
+ setDllDirectory(NULL);
+ }
+
nsresult rv = plugin->Load(outLibrary);
if (NS_FAILED(rv))
*outLibrary = NULL;
+ if (setDllDirectory) {
+ setDllDirectory(L"");
+ }
+
#ifndef WINCE
if (restoreOrigDir) {
BOOL bCheck = SetCurrentDirectoryW(aOrigDir);
NS_ASSERTION(bCheck, "Error in Loading plugin");
}
#endif
return rv;
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -85,16 +85,25 @@ void ExtractEnvironmentFromCL(int &argc,
delete [] delete_argv;
}
}
}
#endif
int wmain(int argc, WCHAR **argv)
{
+ typedef BOOL
+ (WINAPI *pfnSetDllDirectory) (LPCWSTR);
+ pfnSetDllDirectory setDllDirectory =
+ reinterpret_cast<pfnSetDllDirectory>
+ (GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDllDirectoryW"));
+ if (setDllDirectory) {
+ setDllDirectory(L"");
+ }
+
#ifdef XRE_WANT_DLL_BLOCKLIST
SetupDllBlocklist();
#endif
char **argvConverted = new char*[argc + 1];
if (!argvConverted)
return 127;