aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Brown <garbearucla@gmail.com>2014-12-23 17:38:40 -0800
committerGarrett Brown <themagnificentmrb@gmail.com>2015-10-15 07:12:55 -0700
commitf7c966cca634bb8e66664d4d2db882af3dadcd4c (patch)
tree0e2d743123f750331b12e33d460f1c3e60a9b418
parentd74aa78f08d9909980cb7e4264f027705b3b7c38 (diff)
[dllLoader] Fix segfault if high-order word is zero
If the high-order word is zero, then lpProcName is the function's ordinal value. See documentation for GetProcAddress(): - https://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx
-rw-r--r--xbmc/cores/DllLoader/Win32DllLoader.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/xbmc/cores/DllLoader/Win32DllLoader.cpp b/xbmc/cores/DllLoader/Win32DllLoader.cpp
index 231501f570..e9b25a39f1 100644
--- a/xbmc/cores/DllLoader/Win32DllLoader.cpp
+++ b/xbmc/cores/DllLoader/Win32DllLoader.cpp
@@ -31,6 +31,8 @@
#include "exports/emu_kernel32.h"
#include "exports/emu_msvcrt.h"
+#include <limits>
+
extern "C" FILE _iob[];
extern "C" FARPROC WINAPI dllWin32GetProcAddress(HMODULE hModule, LPCSTR function);
@@ -424,10 +426,14 @@ bool Win32DllLoader::ResolveOrdinal(const char *dllName, unsigned long ordinal,
extern "C" FARPROC __stdcall dllWin32GetProcAddress(HMODULE hModule, LPCSTR function)
{
- // first check whether this function is one of the ones we need to wrap
- void *fixup = NULL;
- if (FunctionNeedsWrapping(win32_exports, function, &fixup))
- return (FARPROC)fixup;
+ // if the high-order word is zero, then lpProcName is the function's ordinal value
+ if (reinterpret_cast<uintptr_t>(function) > std::numeric_limits<WORD>::max())
+ {
+ // first check whether this function is one of the ones we need to wrap
+ void *fixup = NULL;
+ if (FunctionNeedsWrapping(win32_exports, function, &fixup))
+ return (FARPROC)fixup;
+ }
// Nope
return GetProcAddress(hModule, function);