add write-after-free tests with potential reuse
This commit is contained in:
parent
5fa6e01929
commit
57d5ab769b
@ -8,7 +8,9 @@ EXECUTABLES := \
|
|||||||
read_after_free_large \
|
read_after_free_large \
|
||||||
read_after_free_small \
|
read_after_free_small \
|
||||||
write_after_free_large \
|
write_after_free_large \
|
||||||
|
write_after_free_large_reuse \
|
||||||
write_after_free_small \
|
write_after_free_small \
|
||||||
|
write_after_free_small_reuse \
|
||||||
read_zero_size \
|
read_zero_size \
|
||||||
write_zero_size \
|
write_zero_size \
|
||||||
invalid_free_protected \
|
invalid_free_protected \
|
||||||
|
14
test/simple-memory-corruption/write_after_free_large_reuse.c
Normal file
14
test/simple-memory-corruption/write_after_free_large_reuse.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
char *p = malloc(128 * 1024);
|
||||||
|
if (!p) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
char *q = malloc(128 * 1024);
|
||||||
|
p[64 * 1024 + 1] = 'a';
|
||||||
|
return 0;
|
||||||
|
}
|
20
test/simple-memory-corruption/write_after_free_small_reuse.c
Normal file
20
test/simple-memory-corruption/write_after_free_small_reuse.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
char *p = malloc(128);
|
||||||
|
if (!p) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
char *q = malloc(128);
|
||||||
|
|
||||||
|
p[65] = 'a';
|
||||||
|
|
||||||
|
// trigger reuse of the allocation
|
||||||
|
for (size_t i = 0; i < 100000; i++) {
|
||||||
|
free(malloc(128));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user