Martin's Tex-Blog

Posts on programming and generally technical topics

Finding buffer overruns and other heap corruptions under Windows

leave a comment »


Windows SDK comes with great tool called debugging tools – it includes small application called gflags that allows to quickly find all buffer overruns and reads of unallocated memory. Actually I would really like to see it integrated in Visual Studio IDE. So how it works. First you register your application with gflags.exe, and then run it. During program testing, system will throw exceptions each time you do something bad with memory (like read or write unallocated regions). Gflags during each allocation will allocate slightly more memory and mark it as non-commited, so any access to it will result in exception which can be easily cought by Visual Studio – yes, after registration with gflags, you can run your program under VS debugger and catch all exceptions, read callstack and all variable contents.

Here is how you register your application with gflags:

gflags /p /enable pheap-buggy.exe /full
(http://msdn.microsoft.com/en-us/library/windows/hardware/ff543097%28v=vs.85%29.aspx)

so even if your program runs flawlessly, use gflags to find bugs in regions which you would never suspect

Advertisement

Written by Marcin

March 14, 2012 at 11:24 pm

Posted in Visual Studio, Windows

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: