add simple string overflow test
This commit is contained in:
19
test/simple-memory-corruption/string_overflow.c
Normal file
19
test/simple-memory-corruption/string_overflow.c
Normal file
@ -0,0 +1,19 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user