mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-12-30 01:46:16 -05:00
add basic invalid free tests
This commit is contained in:
parent
97b693d862
commit
0a79e82474
@ -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 \
|
||||
|
14
test/simple-memory-corruption/invalid_free_protected.c
Normal file
14
test/simple-memory-corruption/invalid_free_protected.c
Normal 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;
|
||||
}
|
12
test/simple-memory-corruption/invalid_free_small_region.c
Normal file
12
test/simple-memory-corruption/invalid_free_small_region.c
Normal 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;
|
||||
}
|
14
test/simple-memory-corruption/invalid_free_unprotected.c
Normal file
14
test/simple-memory-corruption/invalid_free_unprotected.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user