mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-10-31 00:06:33 +01:00 
			
		
		
		
	add simple string overflow test
This commit is contained in:
		
							parent
							
								
									b24569b6ca
								
							
						
					
					
						commit
						93fcc6a978
					
				
					 2 changed files with 20 additions and 0 deletions
				
			
		|  | @ -20,6 +20,7 @@ EXECUTABLES := \ | |||
|     uninitialized_malloc_usable_size \
 | ||||
|     eight_byte_overflow_small \
 | ||||
|     eight_byte_overflow_large \
 | ||||
|     string_overflow | ||||
| 
 | ||||
| all: $(EXECUTABLES) | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										19
									
								
								test/simple-memory-corruption/string_overflow.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/simple-memory-corruption/string_overflow.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| 
 | ||||
| #include <malloc.h> | ||||
| 
 | ||||
| __attribute__((optimize(0))) | ||||
| int main(void) { | ||||
|     char *p = malloc(16); | ||||
|     if (!p) { | ||||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
|     size_t size = malloc_usable_size(p); | ||||
|     memset(p, 'a', size); | ||||
|     printf("overflow by %zu bytes\n", strlen(p) - size); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
		Loading…
	
	Add table
		
		Reference in a new issue