Skip to content
AgileLogics
5 min read

Security Fundamentals

Prerequisites: Performance optimization & profiling

C's lack of automatic bounds checking makes memory-safety bugs a genuine security concern, not just a correctness one:

  • Buffer overflow — writing past the end of a fixed-size buffer (a classic case: gets(), which has no length limit at all and should never be used — use fgets instead, as this course has throughout).
  • Format string vulnerabilities — calling printf(userInput) directly, instead of printf("%s", userInput), lets attacker-controlled % specifiers read or even write arbitrary memory.
  • Integer overflow — an operation exceeding a type's range wraps around silently (for unsigned types) or is undefined behavior (for signed types), which has been the root cause of real buffer-overflow vulnerabilities when an overflowed size is then used for an allocation.

Common mistakes

  • Trusting the length of external input (a file, network data, a command-line argument) without validating it against the actual size of the buffer it's about to be copied into.