arrow_backBack to field notes
WEB SECURITY Published 9 Aug 2026

What Is a Buffer Overflow? A Hands-On Walkthrough

Learn how buffer overflows actually work with a real C example, a stack diagram, and the tools to see it happen yourself.

A buffer overflow happens when a program writes more data into a fixed-size chunk of memory than that chunk can hold. The extra bytes spill into adjacent memory, and depending on what sits next to that buffer, you can corrupt variables, crash the program, or hijack execution flow entirely. It's one of the oldest bug classes in software security and still shows up in CTFs, CVEs, and embedded firmware today.

The vulnerable pattern

Here's a classic example in C:

#include <string.h>

void greet(char *name) {
    char buffer[64];
    strcpy(buffer, name);
}

int main(int argc, char **argv) {
    greet(argv[1]);
    return 0;
}

strcpy copies whatever string you pass it into buffer, with no bounds checking. If argv[1] is longer than 64 bytes, the copy keeps going past the end of the array. On the stack, buffer sits below other local variables, saved registers, and eventually the return address that tells the CPU where to jump after greet() finishes. Overwrite that return address with an address you control, and you control what runs next.

Why this still compiles and runs

C and C++ don't do automatic bounds checking on raw arrays. Functions like strcpy, gets, sprintf, and strcat will happily write past the end of a buffer because they only care about a null terminator or a source length, not the destination's actual size. Compare that to strncpy or snprintf, which take an explicit size argument and stop there. The vulnerability isn't really

Written with AI assistance, reviewed and published by Michal Pilch (CISSP), Korra Studio.

Ready to go further?

This is one note from the Korra Studio knowledge base — the platform pairs every topic with 1-to-1 mentoring.

Get started freearrow_forward