Skip to content

Commit

Permalink
overlay: add runtime check for when GetFnOffsetInModule()'s return va…
Browse files Browse the repository at this point in the history
…lue would have overflowed its return type.

See also #1924
  • Loading branch information
mkrautz committed Nov 24, 2015
1 parent 5f79a3e commit a3e7958
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion overlay/lib.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "overlay_blacklist.h" #include "overlay_blacklist.h"
#include "overlay_exe/overlay_exe.h" #include "overlay_exe/overlay_exe.h"


#undef max // for std::numeric_limits<T>::max()

static HANDLE hMapObject = NULL; static HANDLE hMapObject = NULL;
static HANDLE hHookMutex = NULL; static HANDLE hHookMutex = NULL;
static HHOOK hhookWnd = 0; static HHOOK hhookWnd = 0;
Expand Down Expand Up @@ -817,5 +819,14 @@ int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int ref


unsigned char *fn = reinterpret_cast<unsigned char *>(fnptr); unsigned char *fn = reinterpret_cast<unsigned char *>(fnptr);
unsigned char *base = reinterpret_cast<unsigned char *>(hModule); unsigned char *base = reinterpret_cast<unsigned char *>(hModule);
return fn - base; unsigned long off = static_cast<unsigned long>(fn - base);

// XXX: convert this function to use something other than int.
// Issue mumble-voip/mumble#1924.
if (off > static_cast<unsigned long>(std::numeric_limits<int>::max())) {
ods("Internal overlay error: GetFnOffsetInModule() offset greater than return type can hold.");
return -1;
}

return static_cast<int>(off);
} }

0 comments on commit a3e7958

Please sign in to comment.