Bug 1445601 - Stop using LoadLibraryA in GMP. r=cpearce draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 25 Mar 2018 14:01:59 +0900
changeset 772159 c27119fe1ba026abe69d2ad9a2c671fc955dd294
parent 772158 3beaca8d96d2a48ef44b7d045f12dc0ae7f364c1
push id103861
push userVYV03354@nifty.ne.jp
push dateSun, 25 Mar 2018 05:12:04 +0000
reviewerscpearce
bugs1445601
milestone61.0a1
Bug 1445601 - Stop using LoadLibraryA in GMP. r=cpearce MozReview-Commit-ID: 6krgrVcSHNW
dom/media/gmp/GMPChild.cpp
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -269,38 +269,65 @@ GMPChild::GetAPI(const char* aAPIName,
                  uint32_t aDecryptorId)
 {
   if (!mGMPLoader) {
     return GMPGenericErr;
   }
   return mGMPLoader->GetAPI(aAPIName, aHostAPI, aPluginAPI, aDecryptorId);
 }
 
+#ifdef XP_WIN
+namespace {
+constexpr bool IsASCII(const char* aPtr)
+{
+  for (; *aPtr; ++aPtr) {
+    if (*aPtr & 0x80) {
+      return false;
+    }
+  }
+  return true;
+}
+
+template <size_t N>
+constexpr bool IsASCII(const char *const (&aList)[N])
+{
+  for (size_t i = 0; i < N; ++i) {
+    if (!IsASCII(aList[i])) {
+      return false;
+    }
+  }
+  return true;
+}
+} // anonymous namespace
+#endif
+
 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[] = {
+  constexpr 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
   };
+  static_assert(IsASCII(whitelist),
+    "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());
+        LoadLibraryW(NS_ConvertASCIItoUTF16(lib).get());
         break;
       }
     }
   }
 #endif
   return IPC_OK();
 }