WCU / Cybersecurity
~/CSC 472/Class 05/KP 12
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.