Guarding against re-use of stale object references
Hello all - Dave here...
Tim Burrell of the TwC Security Science team presents the fifth blog installment describing /sdl: functionality in Visual Studio.
-----------------------------------------------------------------------------------------------------------------------------
In the last few posts we described some additional security features that are enabled by the new /sdl compiler switch. Previous comments to posts in this series have highlighted the balance that we have to strike when introducing new security features: some developers/readers welcome new security features in the toolchain and suggest further enhancements; for others conformance and standards compliance takes precedence.
This post describes another feature included under /sdl: in limited circumstances the compiler will instrument C++ operator::delete calls to sanitize the pointer reference. In particular it illustrates a case where we have sought to carefully balance the desire for improved security with that of conformance and avoiding unnecessarily breaking a developer’s valid C++ code.
SDL recommends pointer sanitization
The Security Development Lifecycle (SDL) as implemented at Microsoft recommends (see pages 42-43 of SDL Process Guidance 5.1):
“NULL out free'd memory pointers in new code. This helps reduce the severity of double-free bugs and bugs that overwrite "dangling" pointers. For example:

Add this statement after the delete operator:

A common approac