Add two tests to check that uninitialized read are zeroed

pull/180/head
jvoisin 2021-12-27 13:17:58 +01:00 committed by Daniel Micay
parent 3696f071a4
commit 5f59ee3935
4 changed files with 39 additions and 0 deletions

View File

@ -34,6 +34,8 @@ EXECUTABLES := \
invalid_free_unprotected \ invalid_free_unprotected \
invalid_free_small_region \ invalid_free_small_region \
invalid_free_small_region_far \ invalid_free_small_region_far \
uninitialized_read_small \
uninitialized_read_large \
uninitialized_free \ uninitialized_free \
uninitialized_realloc \ uninitialized_realloc \
uninitialized_malloc_usable_size \ uninitialized_malloc_usable_size \

View File

@ -211,6 +211,15 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
"impossibly_large_malloc") "impossibly_large_malloc")
self.assertEqual(returncode, 0) self.assertEqual(returncode, 0)
def test_uninitialized_read_small(self):
_stdout, stderr, returncode = self.run_test(
"uninitialized_read_small")
self.assertEqual(returncode, 0)
def test_uninitialized_read_large(self):
_stdout, stderr, returncode = self.run_test(
"uninitialized_read_large")
self.assertEqual(returncode, 0)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -0,0 +1,14 @@
#include <stdlib.h>
#include "../test_util.h"
OPTNONE int main(void) {
char *p = malloc(128 * 1024);
for (unsigned i = 0; i < 8; i++) {
if (p[i] != 0) {
return 1;
}
}
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);
for (unsigned i = 0; i < 8; i++) {
if (p[i] != 0) {
return 1;
}
}
free(p);
return 0;
}