What is a buffer overflow?
A buffer overflow happens when a program writes more data into a fixed-size block of memory — a buffer — than that block was allocated to hold. The extra bytes don't vanish: they spill into adjacent memory, overwriting whatever lived next door.
Depending on what sits beside the buffer, that overwrite can corrupt data, change the program's behavior, or hand an attacker control of execution. It's one of the oldest and most studied vulnerability classes in security.
Where it comes from
Classic cases use functions that copy input without checking length against the destination size. The write keeps going past the end of the array:
// 10 bytes reserved on the stack char username[10]; // no length check — input longer than 10 // writes straight past the buffer's end strcpy(username, attacker_input);
The fix is bounds checking: refuse to write more than the buffer can hold, or use length-aware APIs. In the lab on the right, the buffer is char[10] — try to keep your write inside it.