A method and apparatus for detecting a heap smashing condition. A call to a
library function, such as a request to write a data block to the heap
section of a memory, is intercepted from a program being executed. In an
embodiment, a fault-containment wrapper module determines whether
performing the write request would smash the heap. If it would smash the
heap, an error handling procedure is executed instead of writing the data
block. If it would not smash the heap, the fault-containment wrapper
module causes the data block to be written to the memory as requested.