add basic invalid free tests

This commit is contained in:
Daniel Micay 2018-08-24 04:45:48 -04:00
parent 97b693d862
commit 0a79e82474
4 changed files with 43 additions and 0 deletions

View File

@ -9,3 +9,6 @@ all: \
write_after_free_small \
read_zero_size \
write_zero_size \
invalid_free_protected \
invalid_free_unprotected \
invalid_free_small_region \

View File

@ -0,0 +1,14 @@
#include <stdlib.h>
#include <sys/mman.h>
__attribute__((optimize(0)))
int main(void) {
free(malloc(16));
char *p = mmap(NULL, 4096 * 16, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) {
return 1;
}
free(p + 4096 * 8);
return 0;
}

View File

@ -0,0 +1,12 @@
#include <stdlib.h>
__attribute__((optimize(0)))
int main(void) {
char *p = malloc(16);
if (!p) {
return 1;
}
char *q = p + 4096 * 4;
free(q);
return 0;
}

View File

@ -0,0 +1,14 @@
#include <stdlib.h>
#include <sys/mman.h>
__attribute__((optimize(0)))
int main(void) {
free(malloc(16));
char *p = mmap(NULL, 4096 * 16, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) {
return 1;
}
free(p + 4096 * 8);
return 0;
}