add initial simple memory corruption tests
This commit is contained in:
parent
7a86b67778
commit
27ac1e21bc
11
test/simple-memory-corruption/Makefile
Normal file
11
test/simple-memory-corruption/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
all: \
|
||||
double_free_large \
|
||||
double_free_small \
|
||||
unaligned_free_large \
|
||||
unaligned_free_small \
|
||||
read_after_free_large \
|
||||
read_after_free_small \
|
||||
write_after_free_large \
|
||||
write_after_free_small \
|
||||
read_zero_size \
|
||||
write_zero_size \
|
12
test/simple-memory-corruption/double_free_large.c
Normal file
12
test/simple-memory-corruption/double_free_large.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
void *p = malloc(128 * 1024);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
free(p);
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
12
test/simple-memory-corruption/double_free_small.c
Normal file
12
test/simple-memory-corruption/double_free_small.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
void *p = malloc(16);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
free(p);
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
17
test/simple-memory-corruption/read_after_free_large.c
Normal file
17
test/simple-memory-corruption/read_after_free_large.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(128 * 1024);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
memset(p, 'a', 16);
|
||||
free(p);
|
||||
for (size_t i = 0; i < 128 * 1024; i++) {
|
||||
printf("%x\n", p[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
17
test/simple-memory-corruption/read_after_free_small.c
Normal file
17
test/simple-memory-corruption/read_after_free_small.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(16);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
memset(p, 'a', 16);
|
||||
free(p);
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
printf("%x\n", p[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
12
test/simple-memory-corruption/read_zero_size.c
Normal file
12
test/simple-memory-corruption/read_zero_size.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(0);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
printf("%c\n", *p);
|
||||
return 0;
|
||||
}
|
11
test/simple-memory-corruption/unaligned_free_large.c
Normal file
11
test/simple-memory-corruption/unaligned_free_large.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(128 * 1024);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
free(p + 1);
|
||||
return 0;
|
||||
}
|
11
test/simple-memory-corruption/unaligned_free_small.c
Normal file
11
test/simple-memory-corruption/unaligned_free_small.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(16);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
free(p + 1);
|
||||
return 0;
|
||||
}
|
14
test/simple-memory-corruption/write_after_free_large.c
Normal file
14
test/simple-memory-corruption/write_after_free_large.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(128 * 1024);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
free(p);
|
||||
memset(p, 'a', 128 * 1024);
|
||||
return 0;
|
||||
}
|
14
test/simple-memory-corruption/write_after_free_small.c
Normal file
14
test/simple-memory-corruption/write_after_free_small.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(16);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
free(p);
|
||||
memset(p, 'a', 16);
|
||||
return 0;
|
||||
}
|
12
test/simple-memory-corruption/write_zero_size.c
Normal file
12
test/simple-memory-corruption/write_zero_size.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
__attribute__((optimize(0)))
|
||||
int main(void) {
|
||||
char *p = malloc(0);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
*p = 5;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user