Bug 286382 - Don't load DLLs from the current directory; r=bsmedberg a=blocking-betaN+
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 28 Sep 2010 20:33:43 -0400
changeset 55191 6f304a4dfd4d881b9ce8bf2e4671aa836841d58a
parent 55190 0983c1870159839e165ea300b7d221b6bd922ee2
child 55192 4f09e912977d8d5937527e4357b6a9db9eb8d7b9
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, blocking-betaN
bugs286382
milestone2.0b8pre
Bug 286382 - Don't load DLLs from the current directory; r=bsmedberg a=blocking-betaN+
ipc/app/MozillaRuntimeMain.cpp
modules/plugin/base/src/nsPluginsDirWin.cpp
toolkit/xre/nsWindowsWMain.cpp
--- 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;