mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-10-31 08:16:31 +01:00 
			
		
		
		
	test: add regression test for missing init() in realloc()
This commit is contained in:
		
							parent
							
								
									9cb4e6daf6
								
							
						
					
					
						commit
						903cba5a84
					
				
					 4 changed files with 40 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								test/.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								test/.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -40,4 +40,5 @@ overflow_small_1_byte | |||
| overflow_small_8_byte | ||||
| uninitialized_read_large | ||||
| uninitialized_read_small | ||||
| realloc_init | ||||
| __pycache__/ | ||||
|  |  | |||
|  | @ -66,7 +66,8 @@ EXECUTABLES := \ | |||
|     malloc_object_size_offset \
 | ||||
|     invalid_malloc_object_size_small \
 | ||||
|     invalid_malloc_object_size_small_quarantine \
 | ||||
|     impossibly_large_malloc | ||||
|     impossibly_large_malloc \
 | ||||
|     realloc_init | ||||
| 
 | ||||
| all: $(EXECUTABLES) | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										33
									
								
								test/realloc_init.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								test/realloc_init.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | |||
| #include <pthread.h> | ||||
| #include <stdlib.h> | ||||
| 
 | ||||
| static void *thread_func(void *arg) { | ||||
|     arg = realloc(arg, 1024); | ||||
|     if (!arg) { | ||||
|         exit(EXIT_FAILURE); | ||||
|     } | ||||
| 
 | ||||
|     free(arg); | ||||
| 
 | ||||
|     return NULL; | ||||
| } | ||||
| 
 | ||||
| int main(void) { | ||||
|     void *mem = realloc(NULL, 12); | ||||
|     if (!mem) { | ||||
|         return EXIT_FAILURE; | ||||
|     } | ||||
| 
 | ||||
|     pthread_t thread; | ||||
|     int r = pthread_create(&thread, NULL, thread_func, mem); | ||||
|     if (r != 0) { | ||||
|         return EXIT_FAILURE; | ||||
|     } | ||||
| 
 | ||||
|     r = pthread_join(thread, NULL); | ||||
|     if (r != 0) { | ||||
|         return EXIT_FAILURE; | ||||
|     } | ||||
| 
 | ||||
|     return EXIT_SUCCESS; | ||||
| } | ||||
|  | @ -233,6 +233,10 @@ class TestSimpleMemoryCorruption(unittest.TestCase): | |||
|             "uninitialized_read_large") | ||||
|         self.assertEqual(returncode, 0) | ||||
| 
 | ||||
|     def test_realloc_init(self): | ||||
|         _stdout, _stderr, returncode = self.run_test( | ||||
|             "realloc_init") | ||||
|         self.assertEqual(returncode, 0) | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     unittest.main() | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue