mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-12-20 13:24:21 -05:00
add 1 byte overflow tests
This commit is contained in:
parent
13a1f578cb
commit
645414cc9f
test/simple-memory-corruption
@ -39,8 +39,10 @@ EXECUTABLES := \
|
||||
uninitialized_free \
|
||||
uninitialized_realloc \
|
||||
uninitialized_malloc_usable_size \
|
||||
eight_byte_overflow_small \
|
||||
eight_byte_overflow_large \
|
||||
overflow_large_1_byte \
|
||||
overflow_large_8_byte \
|
||||
overflow_small_1_byte \
|
||||
overflow_small_8_byte \
|
||||
string_overflow \
|
||||
delete_type_size_mismatch \
|
||||
unaligned_malloc_usable_size_small \
|
||||
|
14
test/simple-memory-corruption/overflow_large_1_byte.c
Normal file
14
test/simple-memory-corruption/overflow_large_1_byte.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../test_util.h"
|
||||
|
||||
OPTNONE int main(void) {
|
||||
char *p = malloc(256 * 1024);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
size_t size = malloc_usable_size(p);
|
||||
*(p + size) = 0;
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
14
test/simple-memory-corruption/overflow_small_1_byte.c
Normal file
14
test/simple-memory-corruption/overflow_small_1_byte.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../test_util.h"
|
||||
|
||||
OPTNONE int main(void) {
|
||||
char *p = malloc(8);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
size_t size = malloc_usable_size(p);
|
||||
*(p + size) = 1;
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
@ -48,14 +48,26 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
|
||||
self.assertEqual(stderr.decode("utf-8"),
|
||||
"fatal allocator error: double free (quarantine)\n")
|
||||
|
||||
def test_eight_byte_overflow_large(self):
|
||||
def test_overflow_large_1_byte(self):
|
||||
_stdout, _stderr, returncode = self.run_test(
|
||||
"eight_byte_overflow_large")
|
||||
"overflow_large_1_byte")
|
||||
self.assertEqual(returncode, -11)
|
||||
|
||||
def test_eight_byte_overflow_small(self):
|
||||
def test_overflow_large_8_byte(self):
|
||||
_stdout, _stderr, returncode = self.run_test(
|
||||
"overflow_large_8_byte")
|
||||
self.assertEqual(returncode, -11)
|
||||
|
||||
def test_overflow_small_1_byte(self):
|
||||
_stdout, stderr, returncode = self.run_test(
|
||||
"eight_byte_overflow_small")
|
||||
"overflow_small_1_byte")
|
||||
self.assertEqual(returncode, -6)
|
||||
self.assertEqual(stderr.decode("utf-8"),
|
||||
"fatal allocator error: canary corrupted\n")
|
||||
|
||||
def test_overflow_small_8_byte(self):
|
||||
_stdout, stderr, returncode = self.run_test(
|
||||
"overflow_small_8_byte")
|
||||
self.assertEqual(returncode, -6)
|
||||
self.assertEqual(stderr.decode("utf-8"),
|
||||
"fatal allocator error: canary corrupted\n")
|
||||
|
Loading…
Reference in New Issue
Block a user