added tests for malloc_object_size

LDFLAGS is on single line
pull/111/head
rwarr627 2020-06-08 19:21:17 -07:00 committed by Daniel Micay
parent 577524798e
commit 195bc8c92a
5 changed files with 48 additions and 1 deletions

View File

@ -26,4 +26,6 @@ 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
__pycache__/

View File

@ -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 := \
double_free_large \
double_free_large_delayed \
@ -26,7 +40,9 @@ EXECUTABLES := \
delete_type_size_mismatch \
unaligned_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)

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

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

View File

@ -181,6 +181,13 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
_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)
if __name__ == '__main__':
unittest.main()