A buffer overflow occurs when a program writes more data to a buffer than it can hold. Buffers are temporary storage areas in memory, and when they exceed their limits, the excess data can overwrite adjacent memory. This can lead to unexpected behavior, crashes, or security vulnerabilities.
Attackers often exploit buffer overflows to inject malicious code into a program. By carefully crafting the input, they can manipulate the program's execution flow, potentially gaining unauthorized access to systems. Preventing buffer overflows involves using safe coding practices and tools that check for memory limits, such as stack canaries and address space layout randomization.