Skip to content
Permalink
Browse files

overlay: add runtime checks for offset overflow in D3D9.

See also #1924
  • Loading branch information...
mkrautz committed Nov 24, 2015
1 parent a3e7958 commit 114495e59f002531ac9bb02070a1bcbd6652669e
Showing with 22 additions and 4 deletions.
  1. +22 −4 overlay/d3d9.cpp
@@ -32,6 +32,8 @@
#include <d3d9.h>
#include <time.h>

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

This comment has been minimized.

Copy link
@hacst

hacst Nov 25, 2015

Member

Hm. Shouldn't we be compiling with -DNOMINMAX everywhere anyways. Imho this should be fixed in the pro/pri file if there isn't some other strange reason for us needing those macros spawned directly from hell to taunt the living (srsly, what were they thinking...).

This comment has been minimized.

Copy link
@mkrautz

mkrautz Nov 25, 2015

Author Member

If -DNOMINMAX works, then we should use it in compiler.pri, and fix all users of the macros (if any) to use the STL versions.


Direct3D9Data *d3dd = NULL;

typedef IDirect3D9* (WINAPI *pDirect3DCreate9)(UINT SDKVersion) ;
@@ -1041,8 +1043,16 @@ extern "C" __declspec(dllexport) void __cdecl PrepareD3D9() {
} else {
unsigned char *fn = reinterpret_cast<unsigned char *>(pCreate);
unsigned char *base = reinterpret_cast<unsigned char *>(hD3D);
d3dd->iOffsetCreate = fn - base;
ods("D3D9: Successfully found prepatch offset: %p %p %p: %d", hD3D, d3dcreate9, pCreate, d3dd->iOffsetCreate);
unsigned long off = static_cast<unsigned long>(fn - base);

// XXX: convert the offset to use something other than int.
// Issue mumble-voip/mumble#1924.
if (off > static_cast<unsigned long>(std::numeric_limits<int>::max())) {
ods("D3D9: Internal overlay error: CreateDevice offset is > 2GB, does not fit the current data structure.");
} else {
d3dd->iOffsetCreate = static_cast<int>(off);
ods("D3D9: Successfully found prepatch offset: %p %p %p: %d", hD3D, d3dcreate9, pCreate, d3dd->iOffsetCreate);
}
}
id3d9->Release();
}
@@ -1068,8 +1078,16 @@ extern "C" __declspec(dllexport) void __cdecl PrepareD3D9() {
} else {
unsigned char *fn = reinterpret_cast<unsigned char *>(pCreateEx);
unsigned char *base = reinterpret_cast<unsigned char *>(hD3D);
d3dd->iOffsetCreateEx = fn - base;
ods("D3D9: Successfully found prepatch ex offset: %p %p %p: %d", hD3D, d3dcreate9ex, pCreateEx, d3dd->iOffsetCreateEx);
unsigned long off = static_cast<unsigned long>(fn - base);

// XXX: convert the offset to use something other than int.
// Issue mumble-voip/mumble#1924.
if (off > static_cast<unsigned long>(std::numeric_limits<int>::max())) {
ods("D3D9: Internal overlay error: CreateDeviceEx offset is > 2GB, does not fit the current data structure.");
} else {
d3dd->iOffsetCreateEx = static_cast<int>(off);
ods("D3D9: Successfully found prepatch ex offset: %p %p %p: %d", hD3D, d3dcreate9ex, pCreateEx, d3dd->iOffsetCreateEx);
}
}

id3d9->Release();

0 comments on commit 114495e

Please sign in to comment.
You can’t perform that action at this time.