In a software program, buffer overflow occurs when a program, while writing data to a buffer, overruns the buffer size allocated and starts overwriting data to adjacent memory locations.
A buffer can be considered a temporary area in the memory that's allocated to a program to store and retrieve data when needed.
Buffer overflows have been known to be exploited since long back.
When exploiting buffer overflows, our main focus is on overwriting control information so that the flow of control of the program changes, which will allow our code to take control of the program.
Here is a diagram that will give us a basic idea of an overflow in a buffer:
From the preceding diagram, we can assume that this is what a program looks like. Since it is a stack, it starts from the bottom and moves toward the top of the stack.
In the preceding diagram, we can also notice...