Skip to content
Permalink
Browse files

overlay: add runtime check for when GetFnOffsetInModule()'s return va…

…lue would have overflowed its return type.

See also #1924
  • Loading branch information...
mkrautz committed Nov 24, 2015
1 parent 5f79a3e commit a3e7958f1605339560679cbbd3a27de4fd12066c
Showing with 12 additions and 1 deletion.
  1. +12 −1 overlay/lib.cpp
@@ -33,6 +33,8 @@
#include "overlay_blacklist.h"
#include "overlay_exe/overlay_exe.h"

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

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

unsigned char *fn = reinterpret_cast<unsigned char *>(fnptr);
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.
You can’t perform that action at this time.