mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-12-22 14:15:06 -05:00
added tests for malloc_usable_size
This commit is contained in:
parent
19365c25d6
commit
0a3a726c93
3
test/simple-memory-corruption/.gitignore
vendored
3
test/simple-memory-corruption/.gitignore
vendored
@ -23,4 +23,7 @@ write_after_free_large_reuse
|
|||||||
write_after_free_small
|
write_after_free_small
|
||||||
write_after_free_small_reuse
|
write_after_free_small_reuse
|
||||||
write_zero_size
|
write_zero_size
|
||||||
|
unaligned_malloc_usable_size_small
|
||||||
|
invalid_malloc_usable_size_small
|
||||||
|
invalid_malloc_usable_size_small_quarantine
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
@ -23,7 +23,10 @@ EXECUTABLES := \
|
|||||||
eight_byte_overflow_small \
|
eight_byte_overflow_small \
|
||||||
eight_byte_overflow_large \
|
eight_byte_overflow_large \
|
||||||
string_overflow \
|
string_overflow \
|
||||||
delete_type_size_mismatch
|
delete_type_size_mismatch \
|
||||||
|
unaligned_malloc_usable_size_small \
|
||||||
|
invalid_malloc_usable_size_small \
|
||||||
|
invalid_malloc_usable_size_small_quarantine
|
||||||
|
|
||||||
all: $(EXECUTABLES)
|
all: $(EXECUTABLES)
|
||||||
|
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
char *p = malloc(16);
|
||||||
|
if (!p) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
char *q = p + 4096 * 4;
|
||||||
|
malloc_usable_size(q);
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
void *p = malloc(16);
|
||||||
|
if (!p) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
malloc_usable_size(p);
|
||||||
|
return 0;
|
||||||
|
}
|
@ -86,6 +86,20 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
|
|||||||
self.assertEqual(stderr.decode("utf-8"),
|
self.assertEqual(stderr.decode("utf-8"),
|
||||||
"fatal allocator error: invalid free\n")
|
"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):
|
def test_read_after_free_large(self):
|
||||||
_stdout, _stderr, returncode = self.run_test("read_after_free_large")
|
_stdout, _stderr, returncode = self.run_test("read_after_free_large")
|
||||||
self.assertEqual(returncode, -11)
|
self.assertEqual(returncode, -11)
|
||||||
@ -117,6 +131,13 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
|
|||||||
self.assertEqual(stderr.decode("utf-8"),
|
self.assertEqual(stderr.decode("utf-8"),
|
||||||
"fatal allocator error: invalid unaligned free\n")
|
"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):
|
def test_uninitialized_free(self):
|
||||||
_stdout, stderr, returncode = self.run_test("uninitialized_free")
|
_stdout, stderr, returncode = self.run_test("uninitialized_free")
|
||||||
self.assertEqual(returncode, -6)
|
self.assertEqual(returncode, -6)
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
char *p = malloc(16);
|
||||||
|
if (!p) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
malloc_usable_size(p + 1);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user