added tests for if malloc_object_size small allocations are free
This commit is contained in:
		
							
								
								
									
										2
									
								
								test/simple-memory-corruption/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								test/simple-memory-corruption/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -28,4 +28,6 @@ invalid_malloc_usable_size_small
 | 
			
		||||
invalid_malloc_usable_size_small_quarantine
 | 
			
		||||
malloc_object_size
 | 
			
		||||
malloc_object_size_offset
 | 
			
		||||
invalid_malloc_object_size_small
 | 
			
		||||
invalid_malloc_object_size_small_quarantine
 | 
			
		||||
__pycache__/
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,9 @@ EXECUTABLES := \
 | 
			
		||||
	invalid_malloc_usable_size_small \
 | 
			
		||||
	invalid_malloc_usable_size_small_quarantine \
 | 
			
		||||
	malloc_object_size \
 | 
			
		||||
	malloc_object_size_offset
 | 
			
		||||
	malloc_object_size_offset \
 | 
			
		||||
	invalid_malloc_object_size_small \
 | 
			
		||||
	invalid_malloc_object_size_small_quarantine
 | 
			
		||||
 | 
			
		||||
all: $(EXECUTABLES)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
@@ -186,8 +186,24 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
 | 
			
		||||
        self.assertEqual(returncode, 0)
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
    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__':
 | 
			
		||||
    unittest.main()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user