Cisco Systems

  www.cisco.com
  www.cisco.com

Interview Question

Senior Software Engineer Interview San Jose, CA

How would you debug Memory Corruption ?

Answer

Interview Answer

1 Answer

2

Lots of answers to this one. There are some memory bounds-checker type tools, and it's not that complicated to write a basic one from scratch on a decent CPU.
Usually the tools override malloc/free/mmap/... and change them all to mmap protected memory with guard pages before and after the user region. Trying to access beyond the bounds of the region, trying to access a freed region will immediately result in a seg-fault.
Other than that, you can always put some guard data at the beginning and end of every structure and check them occasionally in your code. In many cases you'll be able to see the corrupt data before the program crashes and in some cases you might even be able to identify what data it is (hence where it came from), e.g. strings overriding other data.

Boaz Sedan on Jun 9, 2010

Add Answers or Comments

To comment on this, Sign In or Sign Up.