mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-11-03 01:06:33 +01:00 
			
		
		
		
	Delete test directory
This commit is contained in:
		
							parent
							
								
									4d6456cf58
								
							
						
					
					
						commit
						decddb3811
					
				
					 44 changed files with 0 additions and 963 deletions
				
			
		
							
								
								
									
										5
									
								
								test/.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								test/.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,5 +0,0 @@
 | 
			
		|||
large_array_growth
 | 
			
		||||
mallinfo
 | 
			
		||||
mallinfo2
 | 
			
		||||
malloc_info
 | 
			
		||||
offset
 | 
			
		||||
| 
						 | 
				
			
			@ -1,25 +0,0 @@
 | 
			
		|||
CONFIG_SLAB_CANARY := true
 | 
			
		||||
CONFIG_EXTENDED_SIZE_CLASSES := true
 | 
			
		||||
 | 
			
		||||
ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false))
 | 
			
		||||
    $(error CONFIG_SLAB_CANARY must be true or false)
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
LDLIBS := -lpthread
 | 
			
		||||
 | 
			
		||||
CPPFLAGS += \
 | 
			
		||||
    -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) \
 | 
			
		||||
    -DCONFIG_EXTENDED_SIZE_CLASSES=$(CONFIG_EXTENDED_SIZE_CLASSES)
 | 
			
		||||
 | 
			
		||||
EXECUTABLES := \
 | 
			
		||||
    offset \
 | 
			
		||||
    mallinfo \
 | 
			
		||||
    mallinfo2 \
 | 
			
		||||
    malloc_info \
 | 
			
		||||
    large_array_growth
 | 
			
		||||
 | 
			
		||||
all: $(EXECUTABLES)
 | 
			
		||||
	make -C simple-memory-corruption
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f $(EXECUTABLES)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = NULL;
 | 
			
		||||
    size_t size = 256 * 1024;
 | 
			
		||||
 | 
			
		||||
    for (unsigned i = 0; i < 20; i++) {
 | 
			
		||||
        p = realloc(p, size);
 | 
			
		||||
        if (!p) {
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        memset(p, 'a', size);
 | 
			
		||||
        size = size * 3 / 2;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,39 +0,0 @@
 | 
			
		|||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "test_util.h"
 | 
			
		||||
 | 
			
		||||
static void print_mallinfo(void) {
 | 
			
		||||
    struct mallinfo info = mallinfo();
 | 
			
		||||
    printf("mallinfo:\n");
 | 
			
		||||
    printf("arena: %zu\n", (size_t)info.arena);
 | 
			
		||||
    printf("ordblks: %zu\n", (size_t)info.ordblks);
 | 
			
		||||
    printf("smblks: %zu\n", (size_t)info.smblks);
 | 
			
		||||
    printf("hblks: %zu\n", (size_t)info.hblks);
 | 
			
		||||
    printf("hblkhd: %zu\n", (size_t)info.hblkhd);
 | 
			
		||||
    printf("usmblks: %zu\n", (size_t)info.usmblks);
 | 
			
		||||
    printf("fsmblks: %zu\n", (size_t)info.fsmblks);
 | 
			
		||||
    printf("uordblks: %zu\n", (size_t)info.uordblks);
 | 
			
		||||
    printf("fordblks: %zu\n", (size_t)info.fordblks);
 | 
			
		||||
    printf("keepcost: %zu\n", (size_t)info.keepcost);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *a[4];
 | 
			
		||||
 | 
			
		||||
    a[0] = malloc(1024 * 1024 * 1024);
 | 
			
		||||
    a[1] = malloc(16);
 | 
			
		||||
    a[2] = malloc(32);
 | 
			
		||||
    a[3] = malloc(64);
 | 
			
		||||
 | 
			
		||||
    print_mallinfo();
 | 
			
		||||
 | 
			
		||||
    free(a[0]);
 | 
			
		||||
    free(a[1]);
 | 
			
		||||
    free(a[2]);
 | 
			
		||||
    free(a[3]);
 | 
			
		||||
 | 
			
		||||
    printf("\n");
 | 
			
		||||
    print_mallinfo();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,39 +0,0 @@
 | 
			
		|||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "test_util.h"
 | 
			
		||||
 | 
			
		||||
static void print_mallinfo2(void) {
 | 
			
		||||
    struct mallinfo2 info = mallinfo2();
 | 
			
		||||
    printf("mallinfo2:\n");
 | 
			
		||||
    printf("arena: %zu\n", (size_t)info.arena);
 | 
			
		||||
    printf("ordblks: %zu\n", (size_t)info.ordblks);
 | 
			
		||||
    printf("smblks: %zu\n", (size_t)info.smblks);
 | 
			
		||||
    printf("hblks: %zu\n", (size_t)info.hblks);
 | 
			
		||||
    printf("hblkhd: %zu\n", (size_t)info.hblkhd);
 | 
			
		||||
    printf("usmblks: %zu\n", (size_t)info.usmblks);
 | 
			
		||||
    printf("fsmblks: %zu\n", (size_t)info.fsmblks);
 | 
			
		||||
    printf("uordblks: %zu\n", (size_t)info.uordblks);
 | 
			
		||||
    printf("fordblks: %zu\n", (size_t)info.fordblks);
 | 
			
		||||
    printf("keepcost: %zu\n", (size_t)info.keepcost);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *a[4];
 | 
			
		||||
 | 
			
		||||
    a[0] = malloc(1024 * 1024 * 1024);
 | 
			
		||||
    a[1] = malloc(16);
 | 
			
		||||
    a[2] = malloc(32);
 | 
			
		||||
    a[3] = malloc(64);
 | 
			
		||||
 | 
			
		||||
    print_mallinfo2();
 | 
			
		||||
 | 
			
		||||
    free(a[0]);
 | 
			
		||||
    free(a[1]);
 | 
			
		||||
    free(a[2]);
 | 
			
		||||
    free(a[3]);
 | 
			
		||||
 | 
			
		||||
    printf("\n");
 | 
			
		||||
    print_mallinfo2();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,30 +0,0 @@
 | 
			
		|||
#include <pthread.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE static void leak_memory(void) {
 | 
			
		||||
    (void)malloc(1024 * 1024 * 1024);
 | 
			
		||||
    (void)malloc(16);
 | 
			
		||||
    (void)malloc(32);
 | 
			
		||||
    (void)malloc(4096);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *do_work(void *p) {
 | 
			
		||||
    leak_memory();
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(void) {
 | 
			
		||||
    pthread_t thread[4];
 | 
			
		||||
    for (int i = 0; i < 4; i++) {
 | 
			
		||||
        pthread_create(&thread[i], NULL, do_work, NULL);
 | 
			
		||||
    }
 | 
			
		||||
    for (int i = 0; i < 4; i++) {
 | 
			
		||||
        pthread_join(thread[i], NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    malloc_info(0, stdout);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,50 +0,0 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
static size_t size_classes[] = {
 | 
			
		||||
    /* large */ 4 * 1024 * 1024,
 | 
			
		||||
    /* 0 */ 0,
 | 
			
		||||
    /* 16 */ 16, 32, 48, 64, 80, 96, 112, 128,
 | 
			
		||||
    /* 32 */ 160, 192, 224, 256,
 | 
			
		||||
    /* 64 */ 320, 384, 448, 512,
 | 
			
		||||
    /* 128 */ 640, 768, 896, 1024,
 | 
			
		||||
    /* 256 */ 1280, 1536, 1792, 2048,
 | 
			
		||||
    /* 512 */ 2560, 3072, 3584, 4096,
 | 
			
		||||
    /* 1024 */ 5120, 6144, 7168, 8192,
 | 
			
		||||
    /* 2048 */ 10240, 12288, 14336, 16384,
 | 
			
		||||
#if CONFIG_EXTENDED_SIZE_CLASSES
 | 
			
		||||
    /* 4096 */ 20480, 24576, 28672, 32768,
 | 
			
		||||
    /* 8192 */ 40960, 49152, 57344, 65536,
 | 
			
		||||
    /* 16384 */ 81920, 98304, 114688, 131072,
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define N_SIZE_CLASSES (sizeof(size_classes) / sizeof(size_classes[0]))
 | 
			
		||||
 | 
			
		||||
static const size_t canary_size = SLAB_CANARY ? sizeof(uint64_t) : 0;
 | 
			
		||||
 | 
			
		||||
int main(void) {
 | 
			
		||||
    for (unsigned i = 2; i < N_SIZE_CLASSES; i++) {
 | 
			
		||||
        size_classes[i] -= canary_size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void *p[N_SIZE_CLASSES];
 | 
			
		||||
    for (unsigned i = 0; i < N_SIZE_CLASSES; i++) {
 | 
			
		||||
        size_t size = size_classes[i];
 | 
			
		||||
        p[i] = malloc(size);
 | 
			
		||||
        if (!p[i]) {
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        void *q = malloc(size);
 | 
			
		||||
        if (!q) {
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i != 0) {
 | 
			
		||||
            printf("%zu to %zu: %zd\n", size_classes[i - 1], size, p[i] - p[i - 1]);
 | 
			
		||||
        }
 | 
			
		||||
        printf("%zu to %zu: %zd\n", size, size, q - p[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								test/simple-memory-corruption/.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										33
									
								
								test/simple-memory-corruption/.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,33 +0,0 @@
 | 
			
		|||
delete_type_size_mismatch
 | 
			
		||||
double_free_large
 | 
			
		||||
double_free_large_delayed
 | 
			
		||||
double_free_small
 | 
			
		||||
double_free_small_delayed
 | 
			
		||||
eight_byte_overflow_large
 | 
			
		||||
eight_byte_overflow_small
 | 
			
		||||
invalid_free_protected
 | 
			
		||||
invalid_free_small_region
 | 
			
		||||
invalid_free_small_region_far
 | 
			
		||||
invalid_free_unprotected
 | 
			
		||||
read_after_free_large
 | 
			
		||||
read_after_free_small
 | 
			
		||||
read_zero_size
 | 
			
		||||
string_overflow
 | 
			
		||||
unaligned_free_large
 | 
			
		||||
unaligned_free_small
 | 
			
		||||
uninitialized_free
 | 
			
		||||
uninitialized_malloc_usable_size
 | 
			
		||||
uninitialized_realloc
 | 
			
		||||
write_after_free_large
 | 
			
		||||
write_after_free_large_reuse
 | 
			
		||||
write_after_free_small
 | 
			
		||||
write_after_free_small_reuse
 | 
			
		||||
write_zero_size
 | 
			
		||||
unaligned_malloc_usable_size_small
 | 
			
		||||
invalid_malloc_usable_size_small
 | 
			
		||||
invalid_malloc_usable_size_small_quarantine
 | 
			
		||||
malloc_object_size
 | 
			
		||||
malloc_object_size_offset
 | 
			
		||||
invalid_malloc_object_size_small
 | 
			
		||||
invalid_malloc_object_size_small_quarantine
 | 
			
		||||
__pycache__/
 | 
			
		||||
| 
						 | 
				
			
			@ -1,52 +0,0 @@
 | 
			
		|||
dir=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
 | 
			
		||||
 | 
			
		||||
CONFIG_SLAB_CANARY := true
 | 
			
		||||
 | 
			
		||||
ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false))
 | 
			
		||||
    $(error CONFIG_SLAB_CANARY must be true or false)
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
CFLAGS += -DSLAB_CANARY=$(CONFIG_SLAB_CANARY)
 | 
			
		||||
 | 
			
		||||
LDLIBS := -lhardened_malloc
 | 
			
		||||
 | 
			
		||||
LDFLAGS := -Wl,-L$(dir)../../,-R,$(dir)../../
 | 
			
		||||
 | 
			
		||||
EXECUTABLES := \
 | 
			
		||||
    double_free_large \
 | 
			
		||||
    double_free_large_delayed \
 | 
			
		||||
    double_free_small \
 | 
			
		||||
    double_free_small_delayed \
 | 
			
		||||
    unaligned_free_large \
 | 
			
		||||
    unaligned_free_small \
 | 
			
		||||
    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 \
 | 
			
		||||
    invalid_free_unprotected \
 | 
			
		||||
    invalid_free_small_region \
 | 
			
		||||
    invalid_free_small_region_far \
 | 
			
		||||
    uninitialized_free \
 | 
			
		||||
    uninitialized_realloc \
 | 
			
		||||
    uninitialized_malloc_usable_size \
 | 
			
		||||
    eight_byte_overflow_small \
 | 
			
		||||
    eight_byte_overflow_large \
 | 
			
		||||
    string_overflow \
 | 
			
		||||
    delete_type_size_mismatch \
 | 
			
		||||
    unaligned_malloc_usable_size_small \
 | 
			
		||||
    invalid_malloc_usable_size_small \
 | 
			
		||||
    invalid_malloc_usable_size_small_quarantine \
 | 
			
		||||
    malloc_object_size \
 | 
			
		||||
    malloc_object_size_offset \
 | 
			
		||||
    invalid_malloc_object_size_small \
 | 
			
		||||
    invalid_malloc_object_size_small_quarantine
 | 
			
		||||
 | 
			
		||||
all: $(EXECUTABLES)
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f $(EXECUTABLES)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,14 +0,0 @@
 | 
			
		|||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
struct foo {
 | 
			
		||||
    uint64_t a, b, c, d;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = new char;
 | 
			
		||||
    struct foo *c = (struct foo *)p;
 | 
			
		||||
    delete c;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = malloc(128 * 1024);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
    free(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = malloc(128 * 1024);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    void *q = malloc(128 * 1024);
 | 
			
		||||
    if (!q) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
    free(q);
 | 
			
		||||
    free(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
    free(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    void *q = malloc(16);
 | 
			
		||||
    if (!q) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
    free(q);
 | 
			
		||||
    free(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(256 * 1024);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    *(p + 256 * 1024 + 7) = 0;
 | 
			
		||||
    free(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(8);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    *(p + 8 + 7) = 0;
 | 
			
		||||
    free(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,15 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE 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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    char *q = p + 4096 * 4;
 | 
			
		||||
    free(q);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    char *q = p + 1024 * 1024 * 1024;
 | 
			
		||||
    free(q);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,15 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE 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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,14 +0,0 @@
 | 
			
		|||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
size_t malloc_object_size(void *ptr);
 | 
			
		||||
 | 
			
		||||
__attribute__((optimize(0)))
 | 
			
		||||
int main() {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    char *q = p + 4096 * 4;
 | 
			
		||||
    malloc_object_size(q);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,14 +0,0 @@
 | 
			
		|||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
size_t malloc_object_size(void *ptr);
 | 
			
		||||
 | 
			
		||||
__attribute__((optimize(0)))
 | 
			
		||||
int main() {
 | 
			
		||||
    void *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
    malloc_object_size(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    char *q = p + 4096 * 4;
 | 
			
		||||
    malloc_usable_size(q);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
    malloc_usable_size(p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,12 +0,0 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
size_t malloc_object_size(void *ptr);
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    size_t size = malloc_object_size(p);
 | 
			
		||||
    return size != (SLAB_CANARY ? 24 : 32);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,12 +0,0 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
size_t malloc_object_size(void *ptr);
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    size_t size = malloc_object_size(p + 5);
 | 
			
		||||
    return size != (SLAB_CANARY ? 19 : 27);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +0,0 @@
 | 
			
		|||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE 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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +0,0 @@
 | 
			
		|||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE 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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(0);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    printf("%c\n", *p);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    size_t size = malloc_usable_size(p);
 | 
			
		||||
    memset(p, 'a', size);
 | 
			
		||||
    printf("overflow by %zu bytes\n", strlen(p) - size);
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,211 +0,0 @@
 | 
			
		|||
import os
 | 
			
		||||
import subprocess
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestSimpleMemoryCorruption(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def setUpClass(self):
 | 
			
		||||
        self.dir = os.path.dirname(os.path.realpath(__file__))
 | 
			
		||||
 | 
			
		||||
    def run_test(self, test_name):
 | 
			
		||||
        sub = subprocess.Popen(self.dir + "/" + test_name,
 | 
			
		||||
                               stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 | 
			
		||||
        stdout, stderr = sub.communicate()
 | 
			
		||||
        return stdout, stderr, sub.returncode
 | 
			
		||||
 | 
			
		||||
    def test_delete_type_size_mismatch(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "delete_type_size_mismatch")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode(
 | 
			
		||||
            "utf-8"), "fatal allocator error: sized deallocation mismatch (small)\n")
 | 
			
		||||
 | 
			
		||||
    def test_double_free_large_delayed(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "double_free_large_delayed")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid free\n")
 | 
			
		||||
 | 
			
		||||
    def test_double_free_large(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("double_free_large")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid free\n")
 | 
			
		||||
 | 
			
		||||
    def test_double_free_small_delayed(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "double_free_small_delayed")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: double free (quarantine)\n")
 | 
			
		||||
 | 
			
		||||
    def test_double_free_small(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("double_free_small")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: double free (quarantine)\n")
 | 
			
		||||
 | 
			
		||||
    def test_eight_byte_overflow_large(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test(
 | 
			
		||||
            "eight_byte_overflow_large")
 | 
			
		||||
        self.assertEqual(returncode, -11)
 | 
			
		||||
 | 
			
		||||
    def test_eight_byte_overflow_small(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "eight_byte_overflow_small")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: canary corrupted\n")
 | 
			
		||||
 | 
			
		||||
    def test_invalid_free_protected(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("invalid_free_protected")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid free\n")
 | 
			
		||||
 | 
			
		||||
    def test_invalid_free_small_region_far(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "invalid_free_small_region_far")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode(
 | 
			
		||||
            "utf-8"), "fatal allocator error: invalid free within a slab yet to be used\n")
 | 
			
		||||
 | 
			
		||||
    def test_invalid_free_small_region(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "invalid_free_small_region")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: double free\n")
 | 
			
		||||
 | 
			
		||||
    def test_invalid_free_unprotected(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("invalid_free_unprotected")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid free\n")
 | 
			
		||||
 | 
			
		||||
    def test_invalid_malloc_usable_size_small_quarantene(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "invalid_malloc_usable_size_small_quarantine")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode(
 | 
			
		||||
            "utf-8"), "fatal allocator error: invalid malloc_usable_size (quarantine)\n")
 | 
			
		||||
 | 
			
		||||
    def test_invalid_malloc_usable_size_small(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "invalid_malloc_usable_size_small")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode(
 | 
			
		||||
            "utf-8"), "fatal allocator error: invalid malloc_usable_size\n")
 | 
			
		||||
 | 
			
		||||
    def test_read_after_free_large(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test("read_after_free_large")
 | 
			
		||||
        self.assertEqual(returncode, -11)
 | 
			
		||||
 | 
			
		||||
    def test_read_after_free_small(self):
 | 
			
		||||
        stdout, _stderr, returncode = self.run_test("read_after_free_small")
 | 
			
		||||
        self.assertEqual(returncode, 0)
 | 
			
		||||
        self.assertEqual(stdout.decode("utf-8"),
 | 
			
		||||
                         "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n")
 | 
			
		||||
 | 
			
		||||
    def test_read_zero_size(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test("read_zero_size")
 | 
			
		||||
        self.assertEqual(returncode, -11)
 | 
			
		||||
 | 
			
		||||
    def test_string_overflow(self):
 | 
			
		||||
        stdout, _stderr, returncode = self.run_test("string_overflow")
 | 
			
		||||
        self.assertEqual(returncode, 0)
 | 
			
		||||
        self.assertEqual(stdout.decode("utf-8"), "overflow by 0 bytes\n")
 | 
			
		||||
 | 
			
		||||
    def test_unaligned_free_large(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("unaligned_free_large")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid free\n")
 | 
			
		||||
 | 
			
		||||
    def test_unaligned_free_small(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("unaligned_free_small")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid unaligned free\n")
 | 
			
		||||
 | 
			
		||||
    def test_unaligned_malloc_usable_size_small(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "unaligned_malloc_usable_size_small")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid unaligned malloc_usable_size\n")
 | 
			
		||||
 | 
			
		||||
    def test_uninitialized_free(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("uninitialized_free")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid free\n")
 | 
			
		||||
 | 
			
		||||
    def test_uninitialized_malloc_usable_size(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "uninitialized_malloc_usable_size")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid malloc_usable_size\n")
 | 
			
		||||
 | 
			
		||||
    def test_uninitialized_realloc(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("uninitialized_realloc")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: invalid realloc\n")
 | 
			
		||||
 | 
			
		||||
    def test_write_after_free_large_reuse(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test(
 | 
			
		||||
            "write_after_free_large_reuse")
 | 
			
		||||
        self.assertEqual(returncode, -11)
 | 
			
		||||
 | 
			
		||||
    def test_write_after_free_large(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test("write_after_free_large")
 | 
			
		||||
        self.assertEqual(returncode, -11)
 | 
			
		||||
 | 
			
		||||
    def test_write_after_free_small_reuse(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "write_after_free_small_reuse")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: detected write after free\n")
 | 
			
		||||
 | 
			
		||||
    def test_write_after_free_small(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test("write_after_free_small")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode("utf-8"),
 | 
			
		||||
                         "fatal allocator error: detected write after free\n")
 | 
			
		||||
 | 
			
		||||
    def test_write_zero_size(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test("write_zero_size")
 | 
			
		||||
        self.assertEqual(returncode, -11)
 | 
			
		||||
 | 
			
		||||
    def test_malloc_object_size(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test("malloc_object_size")
 | 
			
		||||
        self.assertEqual(returncode, 0)
 | 
			
		||||
 | 
			
		||||
    def test_malloc_object_size_offset(self):
 | 
			
		||||
        _stdout, _stderr, returncode = self.run_test(
 | 
			
		||||
            "malloc_object_size_offset")
 | 
			
		||||
        self.assertEqual(returncode, 0)
 | 
			
		||||
 | 
			
		||||
    def test_invalid_malloc_object_size_small(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "invalid_malloc_object_size_small")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode(
 | 
			
		||||
            "utf-8"), "fatal allocator error: invalid malloc_object_size\n")
 | 
			
		||||
 | 
			
		||||
    def test_invalid_malloc_object_size_small_quarantine(self):
 | 
			
		||||
        _stdout, stderr, returncode = self.run_test(
 | 
			
		||||
            "invalid_malloc_object_size_small_quarantine")
 | 
			
		||||
        self.assertEqual(returncode, -6)
 | 
			
		||||
        self.assertEqual(stderr.decode(
 | 
			
		||||
            "utf-8"), "fatal allocator error: invalid malloc_object_size (quarantine)\n")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    unittest.main()
 | 
			
		||||
| 
						 | 
				
			
			@ -1,12 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(128 * 1024);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p + 1);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,12 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p + 1);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,12 +0,0 @@
 | 
			
		|||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    malloc_usable_size(p + 1);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    free((void *)1);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +0,0 @@
 | 
			
		|||
#include <malloc.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    malloc_usable_size((void *)1);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,11 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    void *p = realloc((void *)1, 16);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,14 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(128 * 1024);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
    p[64 * 1024 + 1] = 'a';
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,15 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE 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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(128);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    free(p);
 | 
			
		||||
 | 
			
		||||
    p[65] = 'a';
 | 
			
		||||
 | 
			
		||||
    // trigger reuse of the allocation
 | 
			
		||||
    for (size_t i = 0; i < 100000; i++) {
 | 
			
		||||
        free(malloc(128));
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,21 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE 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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,13 +0,0 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include "../test_util.h"
 | 
			
		||||
 | 
			
		||||
OPTNONE int main(void) {
 | 
			
		||||
    char *p = malloc(0);
 | 
			
		||||
    if (!p) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    *p = 5;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,10 +0,0 @@
 | 
			
		|||
#ifndef TEST_UTIL_H
 | 
			
		||||
#define TEST_UTIL_H
 | 
			
		||||
 | 
			
		||||
#ifdef __clang__
 | 
			
		||||
#define OPTNONE __attribute__((optnone))
 | 
			
		||||
#else
 | 
			
		||||
#define OPTNONE __attribute__((optimize(0)))
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue