blob: 1c33e5b2facd67c94f7c48ed6c246dc3b75399f5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
// A simple stack overflow: a loop writes 40 bytes into a 16-byte buffer
// when given an argument. Built plain it overwrites the saved frame
// pointer and the return address, and `ret` jumps to 0x4141414141414141;
// built with -fsanitize=address the first byte past the buffer is
// reported. Without an argument it writes 16 and is fine.
#include <stdio.h>
__attribute__((noinline)) static void fill(int n) {
char buf[16];
for (int i = 0; i < n; i++) buf[i] = 'A';
printf("%c\n", buf[0]);
}
int main(int argc, char **argv) {
(void)argv;
fill(argc > 1 ? 40 : 16);
return 0;
}
|