mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	bpo-18407: win32_urandom() uses PY_DWORD_MAX (GH-10656)
CryptGenRandom() maximum size is PY_DWORD_MAX, not INT_MAX. Use DWORD type for the 'chunk' variable Co-Authored-By: Jeremy Kloth <jeremy.kloth@gmail.com>
This commit is contained in:
		
							parent
							
								
									28f468cb19
								
							
						
					
					
						commit
						c48ff73dd6
					
				
					 1 changed files with 2 additions and 4 deletions
				
			
		|  | @ -55,8 +55,6 @@ win32_urandom_init(int raise) | ||||||
| static int | static int | ||||||
| win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise) | win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise) | ||||||
| { | { | ||||||
|     Py_ssize_t chunk; |  | ||||||
| 
 |  | ||||||
|     if (hCryptProv == 0) |     if (hCryptProv == 0) | ||||||
|     { |     { | ||||||
|         if (win32_urandom_init(raise) == -1) { |         if (win32_urandom_init(raise) == -1) { | ||||||
|  | @ -66,8 +64,8 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise) | ||||||
| 
 | 
 | ||||||
|     while (size > 0) |     while (size > 0) | ||||||
|     { |     { | ||||||
|         chunk = size > INT_MAX ? INT_MAX : size; |         DWORD chunk = (DWORD)Py_MIN(size, PY_DWORD_MAX); | ||||||
|         if (!CryptGenRandom(hCryptProv, (DWORD)chunk, buffer)) |         if (!CryptGenRandom(hCryptProv, chunk, buffer)) | ||||||
|         { |         { | ||||||
|             /* CryptGenRandom() failed */ |             /* CryptGenRandom() failed */ | ||||||
|             if (raise) { |             if (raise) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner