Bug 1330529 - Part 2: Remove unused SetDllDirectory workaround for Shockwave Player plugin. r?jimm draft
authorChris Peterson <cpeterson@mozilla.com>
Fri, 02 Feb 2018 22:34:19 -0800
changeset 755994 e43c32fed2a835b92be3a869c5ea972b2bd8f1fd
parent 755833 994a8d6eccbcdc6106794705bd77e3ac5f031be2
child 755995 cedb99c58e7b22fea666a54849c4e2e2d973b514
push id99356
push usercpeterson@mozilla.com
push dateFri, 16 Feb 2018 08:57:25 +0000
reviewersjimm
bugs1330529, 607832
milestone60.0a1
Bug 1330529 - Part 2: Remove unused SetDllDirectory workaround for Shockwave Player plugin. r?jimm This code was added in bug 607832 to work around a Shockwave Player bug where it tries to load some DLLs from the current directory, but the current directory is not the one it expects. We no longer support the Shockwave Player plugin, so this workaround is no longer necessary and we can always call SetDllDirectory("") to remove the current directory from the DLL search path. MozReview-Commit-ID: C4MjB1SkZE3
dom/plugins/base/nsPluginsDirWin.cpp
dom/plugins/ipc/PluginProcessChild.cpp
--- a/dom/plugins/base/nsPluginsDirWin.cpp
+++ b/dom/plugins/base/nsPluginsDirWin.cpp
@@ -21,51 +21,16 @@
 
 #include "windows.h"
 #include "winbase.h"
 
 #include "nsString.h"
 #include "nsIFile.h"
 #include "nsUnicharUtils.h"
 
-#include <shlwapi.h>
-#define SHOCKWAVE_BASE_FILENAME L"np32dsw"
-/**
- * Determines whether or not SetDllDirectory should be called for this plugin.
- *
- * @param pluginFilePath The full path of the plugin file
- * @return true if SetDllDirectory can be called for the plugin
- */
-bool
-ShouldProtectPluginCurrentDirectory(char16ptr_t pluginFilePath)
-{
-  LPCWSTR passedInFilename = PathFindFileName(pluginFilePath);
-  if (!passedInFilename) {
-    return true;
-  }
-
-  // Somewhere in the middle of 11.6 version of Shockwave, naming of the DLL
-  // after its version number is introduced.
-  if (!wcsicmp(passedInFilename, SHOCKWAVE_BASE_FILENAME L".dll")) {
-    return false;
-  }
-
-  // Shockwave versions before 1202122 will break if you call SetDllDirectory
-  const uint64_t kFixedShockwaveVersion = 1202122;
-  uint64_t version;
-  int found = swscanf(passedInFilename, SHOCKWAVE_BASE_FILENAME L"_%llu.dll",
-                      &version);
-  if (found && version < kFixedShockwaveVersion) {
-    return false;
-  }
-
-  // We always want to call SetDllDirectory otherwise
-  return true;
-}
-
 using namespace mozilla;
 
 /* Local helper functions */
 
 static char* GetKeyValue(void* verbuf, const WCHAR* key,
                          UINT language, UINT codepage)
 {
   WCHAR keybuf[64]; // plenty for the template below, with the longest key
@@ -278,48 +243,41 @@ nsPluginFile::~nsPluginFile()
  * Loads the plugin into memory using NSPR's shared-library loading
  * mechanism. Handles platform differences in loading shared libraries.
  */
 nsresult nsPluginFile::LoadPlugin(PRLibrary **outLibrary)
 {
   if (!mPlugin)
     return NS_ERROR_NULL_POINTER;
 
-  bool protectCurrentDirectory = true;
-
   nsAutoString pluginFilePath;
   mPlugin->GetPath(pluginFilePath);
-  protectCurrentDirectory =
-    ShouldProtectPluginCurrentDirectory(pluginFilePath.BeginReading());
 
   nsAutoString pluginFolderPath = pluginFilePath;
   int32_t idx = pluginFilePath.RFindChar('\\');
   pluginFolderPath.SetLength(idx);
 
   BOOL restoreOrigDir = FALSE;
   WCHAR aOrigDir[MAX_PATH + 1];
   DWORD dwCheck = GetCurrentDirectoryW(MAX_PATH, aOrigDir);
   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");
   }
 
-  if (protectCurrentDirectory) {
-    SetDllDirectory(nullptr);
-  }
+  // Temporarily add the current directory back to the DLL load path.
+  SetDllDirectory(nullptr);
 
   nsresult rv = mPlugin->Load(outLibrary);
   if (NS_FAILED(rv))
       *outLibrary = nullptr;
 
-  if (protectCurrentDirectory) {
-    SetDllDirectory(L"");
-  }
+  SetDllDirectory(L"");
 
   if (restoreOrigDir) {
     DebugOnly<BOOL> bCheck = SetCurrentDirectoryW(aOrigDir);
     NS_ASSERTION(bCheck, "Error in Loading plugin");
   }
 
   return rv;
 }
--- a/dom/plugins/ipc/PluginProcessChild.cpp
+++ b/dom/plugins/ipc/PluginProcessChild.cpp
@@ -18,17 +18,16 @@
 #if defined(XP_MACOSX)
 #include "nsCocoaFeatures.h"
 // An undocumented CoreGraphics framework method, present in the same form
 // since at least OS X 10.5.
 extern "C" CGError CGSSetDebugOptions(int options);
 #endif
 
 #ifdef XP_WIN
-bool ShouldProtectPluginCurrentDirectory(char16ptr_t pluginFilePath);
 #if defined(MOZ_SANDBOX)
 #include "mozilla/sandboxTarget.h"
 #endif
 #endif
 
 using mozilla::ipc::IOThreadChild;
 
 #ifdef OS_WIN
@@ -106,20 +105,18 @@ 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");
 
-    if (ShouldProtectPluginCurrentDirectory(values[0].c_str())) {
-        SanitizeEnvironmentVariables();
-        SetDllDirectory(L"");
-    }
+    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();