Bug 1330529 - Part 3: Protect DLL loads in wmain instead of waiting until PluginProcessChild::Init. r?jimm draft
authorChris Peterson <cpeterson@mozilla.com>
Fri, 02 Feb 2018 22:53:34 -0800
changeset 755995 cedb99c58e7b22fea666a54849c4e2e2d973b514
parent 755994 e43c32fed2a835b92be3a869c5ea972b2bd8f1fd
child 755996 77291c35070a772cd960fad8e6ad7423cdfc490b
push id99356
push usercpeterson@mozilla.com
push dateFri, 16 Feb 2018 08:57:25 +0000
reviewersjimm
bugs1330529
milestone60.0a1
Bug 1330529 - Part 3: Protect DLL loads in wmain instead of waiting until PluginProcessChild::Init. r?jimm Removing #define XRE_DONT_PROTECT_DLL_LOAD from plugin-container.cpp and xpcshell.cpp allows the #included nsWindowsWMain.cpp to protect DLL loads much earlier in the plugin process startup. MozReview-Commit-ID: HbgyfvljvFs
dom/plugins/ipc/PluginProcessChild.cpp
ipc/contentproc/plugin-container.cpp
js/xpconnect/shell/xpcshell.cpp
toolkit/xre/nsWindowsWMain.cpp
--- a/dom/plugins/ipc/PluginProcessChild.cpp
+++ b/dom/plugins/ipc/PluginProcessChild.cpp
@@ -26,17 +26,16 @@ extern "C" CGError CGSSetDebugOptions(in
 #if defined(MOZ_SANDBOX)
 #include "mozilla/sandboxTarget.h"
 #endif
 #endif
 
 using mozilla::ipc::IOThreadChild;
 
 #ifdef OS_WIN
-#include "nsSetDllDirectory.h"
 #include <algorithm>
 #endif
 
 namespace mozilla {
 namespace plugins {
 
 
 bool
@@ -105,19 +104,16 @@ PluginProcessChild::Init(int aArgc, char
     }
 #endif
 
 #elif defined(OS_WIN)
     std::vector<std::wstring> values =
         CommandLine::ForCurrentProcess()->GetLooseValues();
     MOZ_ASSERT(values.size() >= 1, "not enough loose args");
 
-    SanitizeEnvironmentVariables();
-    SetDllDirectory(L"");
-
     pluginFilename = WideToUTF8(values[0]);
 
     // We don't initialize XPCOM but we need the thread manager and the
     // logging framework for the FunctionBroker.
     NS_SetMainThread();
     mozilla::TimeStamp::Startup();
     NS_LogInit();
     mozilla::LogModule::Init();
--- a/ipc/contentproc/plugin-container.cpp
+++ b/ipc/contentproc/plugin-container.cpp
@@ -6,20 +6,17 @@
 
 #include "nsXPCOM.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/Bootstrap.h"
 
 #ifdef XP_WIN
 #include <windows.h>
 // we want a wmain entry point
-// but we don't want its DLL load protection, because we'll handle it here
-#define XRE_DONT_PROTECT_DLL_LOAD
 #include "nsWindowsWMain.cpp"
-#include "nsSetDllDirectory.h"
 #else
 // FIXME/cjones testing
 #include <unistd.h>
 #endif
 
 #if defined(XP_WIN) && defined(MOZ_SANDBOX)
 #include "mozilla/sandboxing/SandboxInitialization.h"
 #include "mozilla/sandboxing/sandboxLogging.h"
@@ -45,21 +42,11 @@ content_process_main(mozilla::Bootstrap*
         }
 
         childData.ProvideLogFunction = mozilla::sandboxing::ProvideLogFunction;
     }
 #endif
 
     bootstrap->XRE_SetProcessType(argv[--argc]);
 
-#ifdef XP_WIN
-    // For plugins, this is done in PluginProcessChild::Init, as we need to
-    // avoid it for unsupported plugins.  See PluginProcessChild::Init for
-    // the details.
-    if (bootstrap->XRE_GetProcessType() != GeckoProcessType_Plugin) {
-        mozilla::SanitizeEnvironmentVariables();
-        SetDllDirectoryW(L"");
-    }
-#endif
-
     nsresult rv = bootstrap->XRE_InitChildProcess(argc, argv, &childData);
     return NS_FAILED(rv);
 }
--- a/js/xpconnect/shell/xpcshell.cpp
+++ b/js/xpconnect/shell/xpcshell.cpp
@@ -15,17 +15,16 @@
 #ifdef XP_MACOSX
 #include "xpcshellMacUtils.h"
 #endif
 #ifdef XP_WIN
 #include <windows.h>
 #include <shlobj.h>
 
 // we want a wmain entry point
-#define XRE_DONT_PROTECT_DLL_LOAD
 #define XRE_WANT_ENVIRON
 #include "nsWindowsWMain.cpp"
 #ifdef MOZ_SANDBOX
 #include "mozilla/sandboxing/SandboxInitialization.h"
 #endif
 #endif
 
 #ifdef MOZ_WIDGET_GTK
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -6,24 +6,22 @@
 // similar bootstrap code. It converts wide-character windows wmain into UTF-8
 // narrow-character strings.
 
 #ifndef XP_WIN
 #error This file only makes sense on Windows.
 #endif
 
 #include "mozilla/Char16.h"
+#include "nsSetDllDirectory.h"
 #include "nsUTF8Utils.h"
+
 #include <intrin.h>
 #include <math.h>
 
-#ifndef XRE_DONT_PROTECT_DLL_LOAD
-#include "nsSetDllDirectory.h"
-#endif
-
 #ifdef __MINGW32__
 
 /* MingW currently does not implement a wide version of the
    startup routines.  Workaround is to implement something like
    it ourselves.  See bug 411826 */
 
 #include <shellapi.h>
 
@@ -74,20 +72,18 @@ FreeAllocStrings(int argc, char **argv)
     delete [] argv[argc];
   }
 
   delete [] argv;
 }
 
 int wmain(int argc, WCHAR **argv)
 {
-#ifndef XRE_DONT_PROTECT_DLL_LOAD
   mozilla::SanitizeEnvironmentVariables();
   SetDllDirectoryW(L"");
-#endif
 
   char **argvConverted = new char*[argc + 1];
   if (!argvConverted)
     return 127;
 
   for (int i = 0; i < argc; ++i) {
     argvConverted[i] = AllocConvertUTF16toUTF8(argv[i]);
     if (!argvConverted[i]) {