Prevention is the best form of protection from application-level threats such as overflows and logic flaws. The following four books discuss secure programming techniques and approaches (primarily with C programming examples across Unix and Windows platforms):
Writing Secure Code, by Michael Howard and David LeBlanc (Microsoft Press)
Secure Coding: Principles and Practices, by Mark Graff and Kenneth van Wyk (O'Reilly Media, Inc.)
Building Secure Software, by Gary McGraw and John Viega (Addison Wesley)
Secure Programming Cookbook for C and C++, by Matt Messier and John Viega (O'Reilly)