Bug 1445601 - Stop using LoadLibraryA in GMP. r=cpearce draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Wed, 28 Mar 2018 00:02:28 +0900
changeset 781698 0e93acecfe0c9ccd2e4ba9ad3126b6ae16433387
parent 781697 cf909f472c1c0007b2ff759d011435b8b6bc0f37
push id106376
push userVYV03354@nifty.ne.jp
push dateFri, 13 Apr 2018 12:58:12 +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();
 }