add 1 byte overflow tests

This commit is contained in:
Daniel Micay 2022-01-03 21:20:15 -05:00
parent 13a1f578cb
commit 645414cc9f
6 changed files with 48 additions and 6 deletions

View File

@ -39,8 +39,10 @@ EXECUTABLES := \
uninitialized_free \ uninitialized_free \
uninitialized_realloc \ uninitialized_realloc \
uninitialized_malloc_usable_size \ uninitialized_malloc_usable_size \
eight_byte_overflow_small \ overflow_large_1_byte \
eight_byte_overflow_large \ overflow_large_8_byte \
overflow_small_1_byte \
overflow_small_8_byte \
string_overflow \ string_overflow \
delete_type_size_mismatch \ delete_type_size_mismatch \
unaligned_malloc_usable_size_small \ unaligned_malloc_usable_size_small \

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

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

View File

@ -48,14 +48,26 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
self.assertEqual(stderr.decode("utf-8"), self.assertEqual(stderr.decode("utf-8"),
"fatal allocator error: double free (quarantine)\n") "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( _stdout, _stderr, returncode = self.run_test(
"eight_byte_overflow_large") "overflow_large_1_byte")
self.assertEqual(returncode, -11) 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( _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(returncode, -6)
self.assertEqual(stderr.decode("utf-8"), self.assertEqual(stderr.decode("utf-8"),
"fatal allocator error: canary corrupted\n") "fatal allocator error: canary corrupted\n")