Skip to content

Commit

Permalink
Bug 1167248: Test whether mysterious rand_s failures are due to LoadL…
Browse files Browse the repository at this point in the history
…ibraryExW hooks. rs=terrence

--HG--
extra : rebase_source : a6c4fd1ee5536f2d9eee6573aa76e82195c0d7d0
  • Loading branch information
David Major committed Jul 7, 2015
1 parent 0b48f59 commit 0de4866
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions js/src/jsmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
# include <unistd.h>
#endif

#ifdef XP_WIN
# include "jswin.h"
#endif

#include "jsapi.h"
#include "jsatom.h"
#include "jscntxt.h"
Expand Down Expand Up @@ -740,7 +744,28 @@ random_generateSeed()
seed.u64 = 0;

#if defined(XP_WIN)
/*
* Temporary diagnostic for bug 1167248: Test whether the injected hooks
* react differently to LoadLibraryW / LoadLibraryExW.
*/
HMODULE oldWay = LoadLibraryW(L"ADVAPI32.DLL");
HMODULE newWay = LoadLibraryExW(L"ADVAPI32.DLL",
nullptr,
LOAD_LIBRARY_SEARCH_SYSTEM32);
/* Fallback for older versions of Windows */
if (!newWay && GetLastError() == ERROR_INVALID_PARAMETER)
newWay = LoadLibraryExW(L"ADVAPI32.DLL", nullptr, 0);

if (oldWay && !newWay)
MOZ_CRASH();

errno_t error = rand_s(&seed.u32[0]);

if (oldWay)
FreeLibrary(oldWay);
if (newWay)
FreeLibrary(newWay);

MOZ_ASSERT(error == 0, "rand_s() error?!");

error = rand_s(&seed.u32[1]);
Expand Down

0 comments on commit 0de4866

Please sign in to comment.