Skip to content

Commit a87633e

Browse files
committed
Issue #25003: os.urandom() doesn't use getentropy() on Solaris because
getentropy() is blocking, whereas os.urandom() should not block. getentropy() is supported since Solaris 11.3.
1 parent f522bbc commit a87633e

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 2.7.11?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #25003: os.urandom() doesn't use getentropy() on Solaris because
14+
getentropy() is blocking, whereas os.urandom() should not block. getentropy()
15+
is supported since Solaris 11.3.
16+
1317
- Issue #21167: NAN operations are now handled correctly when python is
1418
compiled with ICC even if -fp-model strict is not specified.
1519

Python/random.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
9393
return 0;
9494
}
9595

96-
#elif HAVE_GETENTROPY
96+
/* Issue #25003: Don' use getentropy() on Solaris (available since
97+
* Solaris 11.3), it is blocking whereas os.urandom() should not block. */
98+
#elif defined(HAVE_GETENTROPY) && !defined(sun)
99+
#define PY_GETENTROPY 1
100+
97101
/* Fill buffer with size pseudo-random bytes generated by getentropy().
98102
Return 0 on success, or raise an exception and return -1 on error.
99103
If fatal is nonzero, call Py_FatalError() instead of raising an exception
@@ -333,7 +337,7 @@ _PyOS_URandom(void *buffer, Py_ssize_t size)
333337

334338
#ifdef MS_WINDOWS
335339
return win32_urandom((unsigned char *)buffer, size, 1);
336-
#elif HAVE_GETENTROPY
340+
#elif defined(PY_GETENTROPY)
337341
return py_getentropy(buffer, size, 0);
338342
#else
339343
# ifdef __VMS
@@ -396,7 +400,7 @@ _PyRandom_Init(void)
396400
(void)win32_urandom((unsigned char *)secret, secret_size, 0);
397401
#elif __VMS
398402
vms_urandom((unsigned char *)secret, secret_size, 0);
399-
#elif HAVE_GETENTROPY
403+
#elif defined(PY_GETENTROPY)
400404
(void)py_getentropy(secret, secret_size, 1);
401405
#else
402406
dev_urandom_noraise(secret, secret_size);
@@ -412,7 +416,7 @@ _PyRandom_Fini(void)
412416
CryptReleaseContext(hCryptProv, 0);
413417
hCryptProv = 0;
414418
}
415-
#elif HAVE_GETENTROPY
419+
#elif defined(PY_GETENTROPY)
416420
/* nothing to clean */
417421
#else
418422
dev_urandom_close();

0 commit comments

Comments
 (0)