Buffer overflow happens due to an anomaly condition under which more data can be put into a memory area (buffer) than the capacity allocated to the program. Moreover, it will overrun the buffer’s boundary and overwrite other information in the adjacent memory space. Besides, it is a transfer of control to the code supplied by the attacker resulting in the ability to execute malicious code within the privileges of the targeted process. This is a special case of violation of memory safety.
Robust input validation is the best prevention against buffer overflow attacks. Furthermore, using type safe programming languages may help to reduce the attack. In addition, Address Space Layout Randomization (ASLR) is very import control to minimize buffer overflow attacks.