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
--- 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();
}