hardened_malloc/test/simple-memory-corruption/string_overflow.c

20 lines
333 B
C
Raw Normal View History

2018-10-03 23:15:38 +02:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
__attribute__((optimize(0)))
int main(void) {
char *p = malloc(16);
if (!p) {
return 1;
}
size_t size = malloc_usable_size(p);
memset(p, 'a', size);
printf("overflow by %zu bytes\n", strlen(p) - size);
return 0;
}