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>
static int
win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
{
- Py_ssize_t chunk;
-
if (hCryptProv == 0)
{
if (win32_urandom_init(raise) == -1) {
while (size > 0)
{
- chunk = size > INT_MAX ? INT_MAX : size;
- if (!CryptGenRandom(hCryptProv, (DWORD)chunk, buffer))
+ DWORD chunk = (DWORD)Py_MIN(size, PY_DWORD_MAX);
+ if (!CryptGenRandom(hCryptProv, chunk, buffer))
{
/* CryptGenRandom() failed */
if (raise) {