Skip to content

Fix stack-buffer-overflow in Windows thread-naming RaiseException (x64)#420

Open
subhramit wants to merge 1 commit into
ValveSoftware:masterfrom
subhramit:fix-stack-buffer-overflow
Open

Fix stack-buffer-overflow in Windows thread-naming RaiseException (x64)#420
subhramit wants to merge 1 commit into
ValveSoftware:masterfrom
subhramit:fix-stack-buffer-overflow

Conversation

@subhramit

Copy link
Copy Markdown

Fixes #418

On x64, sizeof(DWORD) (4) != sizeof(ULONG_PTR) (8), so sizeof(info)/sizeof(DWORD) evaluates to 6, causing RaiseException to read 48 bytes from the 24-byte THREADNAME_INFO on the stack.
MSVC AddressSanitizer correctly halts on this, so it is harmless at runtime (the extra bytes are valid stack, and __except swallows the exception), but it is an out-of-bounds read, so needed patching.

Change: used sizeof(ULONG_PTR) as the divisor, which is the form given in Microsoft's own documentation and produces the correct count on both x86 and x64.

Signed-off-by: subhramit <subhramit.bb@live.in>
@subhramit

Copy link
Copy Markdown
Author

cc @zpostfacto if you could take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant