Finding buffer overruns and other heap corruptions under Windows
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
Leave a Reply