Writing data beyond the allocated boundaries of a fixed-size buffer.
Writing more data to a buffer than it was allocated to hold overwrites adjacent stack or heap memory addresses, causing security vulnerabilities or stack smashing crashes.
Using unsafe C string functions like `strcpy()`, `gets()`, or `sprintf()` without bounds checks.
1#include <stdio.h>2#include <string.h>3 4int main() {5 char dest[8];6 // Copying a 13-character string into an 8-byte buffer!7 strcpy(dest, "Hello World!!"); // Stack smashing detected!8 return 0;9}1#include <stdio.h>2#include <string.h>3 4int main() {5 char dest[16]; // Sufficiently sized buffer6 7 // Fix: Use bounds-checked functions like strncpy or snprintf8 snprintf(dest, sizeof(dest), "%s", "Hello World!!");9 printf("Result: %s\n", dest);10 return 0;11}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
Destination buffer `dest` can only store 8 bytes (including null terminator). `strcpy` copies 14 bytes into `dest`, overwriting stack frame addresses.