added tests for if malloc_object_size small allocations are free

This commit is contained in:
rwarr627 2020-06-17 18:59:44 -07:00 committed by Daniel Micay
parent de3fb50dcc
commit 7804e263e9
5 changed files with 50 additions and 2 deletions

View File

@ -28,4 +28,6 @@ invalid_malloc_usable_size_small
invalid_malloc_usable_size_small_quarantine invalid_malloc_usable_size_small_quarantine
malloc_object_size malloc_object_size
malloc_object_size_offset malloc_object_size_offset
invalid_malloc_object_size_small
invalid_malloc_object_size_small_quarantine
__pycache__/ __pycache__/

View File

@ -42,7 +42,9 @@ EXECUTABLES := \
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 \
malloc_object_size_offset malloc_object_size_offset \
invalid_malloc_object_size_small \
invalid_malloc_object_size_small_quarantine
all: $(EXECUTABLES) all: $(EXECUTABLES)

View File

@ -0,0 +1,14 @@
#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;
}

View File

@ -0,0 +1,14 @@
#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;
}

View File

@ -186,8 +186,24 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
self.assertEqual(returncode, 0) self.assertEqual(returncode, 0)
def test_malloc_object_size_offset(self): def test_malloc_object_size_offset(self):
_stdout, _stderr, returncode = self.run_test("malloc_object_size_offset") _stdout, _stderr, returncode = self.run_test(
"malloc_object_size_offset")
self.assertEqual(returncode, 0) 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__': if __name__ == '__main__':
unittest.main() unittest.main()