Class 05 · KP 12 / 19
FORTIFY_SOURCE and Safer libc
-D_FORTIFY_SOURCE=2 (with -O1+) swaps unsafe libc calls for checked variants when a buffer size is known at compile time.memcpy → __memcpy_chk, strcpy → __strcpy_chk, sprintf → __sprintf_chk, etc.- If a copy would exceed the object's known size, the program aborts instead of corrupting memory.
- Also hardens
printf against some %n format-string abuses. - Limits: only when size is statically known; heap objects and truly dynamic sizes are not covered.
=3 extends coverage on newer toolchains.