Bug 1445601 - Stop using LoadLibraryA in GMP. r=cpearce
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Wed, 28 Mar 2018 00:02:28 +0900
changeset 782133 4d0b4650e438989ba169b1657b91c5462e9137b6
parent 782132 7a1273c1861c248e52da934eb29f7ab4a21a49ba
child 782134 b8ac8bdb082cd6d362ed29ab11a01ff33eabddb6
push id106487
push userVYV03354@nifty.ne.jp
push dateSat, 14 Apr 2018 12:37:23 +0000
reviewerscpearce
bugs1445601, 1440886
milestone61.0a1
Bug 1445601 - Stop using LoadLibraryA in GMP. r=cpearce We should not use LoadLibraryA (or more generally "A" functions) on Windows because it is lossy. Bug 1440886 will introduce a static analysis to prevent potential misuse of LoadLibraryA, so we need to replace existing usages first. MozReview-Commit-ID: 6krgrVcSHNW
dom/media/gmp/GMPChild.cpp
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -12,16 +12,17 @@
 #include "GMPVideoHost.h"
 #include "nsDebugImpl.h"
 #include "nsExceptionHandler.h"
 #include "nsIFile.h"
 #include "nsXULAppAPI.h"
 #include "gmp-video-decode.h"
 #include "gmp-video-encode.h"
 #include "GMPPlatform.h"
+#include "mozilla/Algorithm.h"
 #include "mozilla/ipc/CrashReporterClient.h"
 #include "mozilla/ipc/ProcessChild.h"
 #include "GMPUtils.h"
 #include "prio.h"
 #include "base/task.h"
 #include "base/command_line.h"
 #include "ChromiumCDMAdapter.h"
 #include "GMPLog.h"
@@ -276,31 +277,36 @@ GMPChild::GetAPI(const char* aAPIName,
 
 mozilla::ipc::IPCResult
 GMPChild::RecvPreloadLibs(const nsCString& aLibs)
 {
 #ifdef XP_WIN
   // Pre-load DLLs that need to be used by the EME plugin but that can't be
   // loaded after the sandbox has started
   // Items in this must be lowercase!
-  static const char *const whitelist[] = {
-    "dxva2.dll", // Get monitor information
-    "evr.dll", // MFGetStrideForBitmapInfoHeader
-    "mfplat.dll", // MFCreateSample, MFCreateAlignedMemoryBuffer, MFCreateMediaType
-    "msmpeg2vdec.dll", // H.264 decoder
-    "psapi.dll", // For GetMappedFileNameW, see bug 1383611
+  constexpr static const char16_t* whitelist[] = {
+    u"dxva2.dll", // Get monitor information
+    u"evr.dll", // MFGetStrideForBitmapInfoHeader
+    u"mfplat.dll", // MFCreateSample, MFCreateAlignedMemoryBuffer, MFCreateMediaType
+    u"msmpeg2vdec.dll", // H.264 decoder
+    u"psapi.dll", // For GetMappedFileNameW, see bug 1383611
   };
+  constexpr static bool (*IsASCII)(const char16_t*) = NS_ConstExprIsAscii;
+  static_assert(AllOf(std::begin(whitelist), std::end(whitelist), IsASCII),
+                "Items in the whitelist must not contain non-ASCII "
+                "characters!");
 
   nsTArray<nsCString> libs;
   SplitAt(", ", aLibs, libs);
   for (nsCString lib : libs) {
     ToLowerCase(lib);
-    for (const char* whiteListedLib : whitelist) {
-      if (lib.EqualsASCII(whiteListedLib)) {
-        LoadLibraryA(lib.get());
+    for (const char16_t* whiteListedLib : whitelist) {
+      if (nsDependentString(whiteListedLib).EqualsASCII(lib.Data(),
+                                                        lib.Length())) {
+        LoadLibraryW(char16ptr_t(whiteListedLib));
         break;
       }
     }
   }
 #endif
   return IPC_OK();
 }