Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78cc2e8

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 3f18f10 commit 78cc2e8

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 @@ Release date: tba
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 #25182: The stdprinter (used as sys.stderr before the io module is
1418
imported at startup) now uses the backslashreplace error handler.
1519

Python/random.c

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

70-
#elif HAVE_GETENTROPY
70+
/* Issue #25003: Don' use getentropy() on Solaris (available since
71+
* Solaris 11.3), it is blocking whereas os.urandom() should not block. */
72+
#elif defined(HAVE_GETENTROPY) && !defined(sun)
73+
#define PY_GETENTROPY 1
74+
7175
/* Fill buffer with size pseudo-random bytes generated by getentropy().
7276
Return 0 on success, or raise an exception and return -1 on error.
7377
@@ -275,7 +279,7 @@ _PyOS_URandom(void *buffer, Py_ssize_t size)
275279

276280
#ifdef MS_WINDOWS
277281
return win32_urandom((unsigned char *)buffer, size, 1);
278-
#elif HAVE_GETENTROPY
282+
#elif defined(PY_GETENTROPY)
279283
return py_getentropy(buffer, size, 0);
280284
#else
281285
return dev_urandom_python((char*)buffer, size);
@@ -322,7 +326,7 @@ _PyRandom_Init(void)
322326
else {
323327
#ifdef MS_WINDOWS
324328
(void)win32_urandom(secret, secret_size, 0);
325-
#elif HAVE_GETENTROPY
329+
#elif defined(PY_GETENTROPY)
326330
(void)py_getentropy(secret, secret_size, 1);
327331
#else
328332
dev_urandom_noraise(secret, secret_size);
@@ -338,7 +342,7 @@ _PyRandom_Fini(void)
338342
CryptReleaseContext(hCryptProv, 0);
339343
hCryptProv = 0;
340344
}
341-
#elif HAVE_GETENTROPY
345+
#elif defined(PY_GETENTROPY)
342346
/* nothing to clean */
343347
#else
344348
dev_urandom_close();

0 commit comments

Comments
 (0)