add write-after-free tests with potential reuse

pull/50/head
Daniel Micay 2018-10-08 17:41:06 -04:00
parent 5fa6e01929
commit 57d5ab769b
3 changed files with 36 additions and 0 deletions

View File

@ -8,7 +8,9 @@ EXECUTABLES := \
read_after_free_large \
read_after_free_small \
write_after_free_large \
write_after_free_large_reuse \
write_after_free_small \
write_after_free_small_reuse \
read_zero_size \
write_zero_size \
invalid_free_protected \

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

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