A buffer overflow occurs when a buffer (i.e., an array) is filled with more data than it can hold. The excess bytes of data are written directly into memory, often causing a segfault and crashing the program.
Vulnerable programs can be explioted to redirect the instruction pointer to point to malicious code or shell code.
Buffer overflows are common in compiled langauges like C and C++, where array boundaries are not checked.
The table below shows several C and C++ functions vulnerable to buffer overflows and their safe alternative: