add initial simple memory corruption tests

pull/50/head
Daniel Micay 2018-08-24 03:09:23 -04:00
parent 7a86b67778
commit 27ac1e21bc
11 changed files with 143 additions and 0 deletions

View 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 \

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

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

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

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

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

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

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

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

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

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