Famous Buffer Overruns

Preventing bufferoverruns

C functions that don't know their inputs

function description safer alternative description
gets read from stdin until '\0' or '\n' and place in buffer fgets can specify maximum length of string to be placed in buffer
strcpy copy from one buffer to another (up to '\0') strncpy specify max amount of data to be copied
strcat(dest, src) copy characters in src to the end of dest strncat only the first n characters of src are appended
sprintf format contents of one buffer and place in another buffer snprintf size of destination buffer is specified
scanf read formatted input from stdin, dangerous if used with an unbounded specifier like %s scanf with bounded
format specifier
used with bounded size format specifiers is ok

The general rule: Know your inputs!!

What to do about it?

Integer overflow

Canonical Naming and Directory Traversal

Heartbleed

Format string vulnerability

What can I trust?