mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:42:43 +00:00 
			
		
		
		
	LibC: __generate_unique_filename(): Replace rand() with arc4random()
LibC stdlib `arc4random()` uses the `getrandom` system call which uses `KernelRng::get_good_random_bytes`. This ensures that filenames generated using functions such as `mkstemp()` are suitably randomised and are no longer predictable.
This commit is contained in:
		
							parent
							
								
									cef6b7b2e4
								
							
						
					
					
						commit
						e8e8d3caf5
					
				
					 1 changed files with 1 additions and 1 deletions
				
			
		|  | @ -186,7 +186,7 @@ __attribute__((warn_unused_result)) int __generate_unique_filename(char* pattern | ||||||
| 
 | 
 | ||||||
|     for (int attempt = 0; attempt < 100; ++attempt) { |     for (int attempt = 0; attempt < 100; ++attempt) { | ||||||
|         for (int i = 0; i < 6; ++i) |         for (int i = 0; i < 6; ++i) | ||||||
|             pattern[start + i] = random_characters[(rand() % (sizeof(random_characters) - 1))]; |             pattern[start + i] = random_characters[(arc4random() % (sizeof(random_characters) - 1))]; | ||||||
|         struct stat st; |         struct stat st; | ||||||
|         int rc = lstat(pattern, &st); |         int rc = lstat(pattern, &st); | ||||||
|         if (rc < 0 && errno == ENOENT) |         if (rc < 0 && errno == ENOENT) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brendan Coles
						Brendan Coles