Presenter notes for Electric Fence, mudflap, and debugging talk
BarCampDenver, August 2006
16:00 MDT
- C/C++ specific -- allows greater control. "Portable assembly language"
- What are memory errors?
- Buffer overflow/underflow
- Memory leaks
- Accessing memory after it's been deleted
- (Tangent: What is the heap? Where can variables be allocated? (static, stack, heap))
The application:
$ g++ -g -Wall buffer.cxx -o buffer
ELECTRIC FENCE
- Written by Bruce Perens for Pixar in 1987.
- How it works: Uses mprotect() syscall to mark pages as invalid.
- (Potential tangent: What are memory pages?)
- Aligns dynamic memory (malloc()/free()) so that it adjoins an invalid page
- Upon deallocation, marks deallocated page as invalid
- Creates segmentation fault on overflow, or invalid use
- Can be linked dynamically; use LD_PRELOAD to invoke at runtime:
$ LD_PRELOAD=libefence.so.0.0.0 ./eftest
- Use gdb options to do the same thing:
(gdb) set environment LD_PRELOAD libefence.so.0.0
- GDB takes you to the exact line that caused the buffer overflow
MUDFLAP
- New for gcc 4 (right?)
- Paper published in 2003 by Frank Eigler
- Does more of what Electric Fence does; also protects against static and stack objects; memory leaks
- Application must use gcc 4, must be recompiled
$ g++ -g -Wall buffer.cxx -o buffer -fmudflap -lmudflap
- Behavior can be controlled at runtime
$ MUDFLAP_OPTIONS=-help ./mudflap