add simple string overflow test

This commit is contained in:
Daniel Micay 2018-10-03 17:15:38 -04:00
parent b24569b6ca
commit 93fcc6a978
2 changed files with 20 additions and 0 deletions

View File

@ -20,6 +20,7 @@ EXECUTABLES := \
uninitialized_malloc_usable_size \ uninitialized_malloc_usable_size \
eight_byte_overflow_small \ eight_byte_overflow_small \
eight_byte_overflow_large \ eight_byte_overflow_large \
string_overflow
all: $(EXECUTABLES) all: $(EXECUTABLES)

View 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;
}