added tests for malloc_object_size
LDFLAGS is on single line
This commit is contained in:
parent
577524798e
commit
195bc8c92a
2
test/simple-memory-corruption/.gitignore
vendored
2
test/simple-memory-corruption/.gitignore
vendored
@ -26,4 +26,6 @@ write_zero_size
|
|||||||
unaligned_malloc_usable_size_small
|
unaligned_malloc_usable_size_small
|
||||||
invalid_malloc_usable_size_small
|
invalid_malloc_usable_size_small
|
||||||
invalid_malloc_usable_size_small_quarantine
|
invalid_malloc_usable_size_small_quarantine
|
||||||
|
malloc_object_size
|
||||||
|
malloc_object_size_offset
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
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 := \
|
EXECUTABLES := \
|
||||||
double_free_large \
|
double_free_large \
|
||||||
double_free_large_delayed \
|
double_free_large_delayed \
|
||||||
@ -26,7 +40,9 @@ EXECUTABLES := \
|
|||||||
delete_type_size_mismatch \
|
delete_type_size_mismatch \
|
||||||
unaligned_malloc_usable_size_small \
|
unaligned_malloc_usable_size_small \
|
||||||
invalid_malloc_usable_size_small \
|
invalid_malloc_usable_size_small \
|
||||||
invalid_malloc_usable_size_small_quarantine
|
invalid_malloc_usable_size_small_quarantine \
|
||||||
|
malloc_object_size \
|
||||||
|
malloc_object_size_offset
|
||||||
|
|
||||||
all: $(EXECUTABLES)
|
all: $(EXECUTABLES)
|
||||||
|
|
||||||
|
11
test/simple-memory-corruption/malloc_object_size.c
Normal file
11
test/simple-memory-corruption/malloc_object_size.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
size_t malloc_object_size(void *ptr);
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
char *p = malloc(16);
|
||||||
|
size_t size = malloc_object_size(p);
|
||||||
|
return size != (SLAB_CANARY ? 24 : 32);
|
||||||
|
}
|
11
test/simple-memory-corruption/malloc_object_size_offset.c
Normal file
11
test/simple-memory-corruption/malloc_object_size_offset.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
size_t malloc_object_size(void *ptr);
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
char *p = malloc(16);
|
||||||
|
size_t size = malloc_object_size(p + 5);
|
||||||
|
return size != (SLAB_CANARY ? 19 : 27);
|
||||||
|
}
|
@ -181,6 +181,13 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
|
|||||||
_stdout, _stderr, returncode = self.run_test("write_zero_size")
|
_stdout, _stderr, returncode = self.run_test("write_zero_size")
|
||||||
self.assertEqual(returncode, -11)
|
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)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user