summaryrefslogtreecommitdiffstats
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-10-01 07:59:32 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-10-01 07:59:32 (GMT)
commit78cc2e89687f3f2b7fd404831a6ea19baccf8c81 (patch)
treeb4f84e00e29f873b5cc2405d0cf0fb4a7a172045 /Python/random.c
parent3f18f10f39a55963e63d544382f0e17668ed97e8 (diff)
downloadcpython-78cc2e89687f3f2b7fd404831a6ea19baccf8c81.zip
cpython-78cc2e89687f3f2b7fd404831a6ea19baccf8c81.tar.gz
cpython-78cc2e89687f3f2b7fd404831a6ea19baccf8c81.tar.bz2
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.
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Python/random.c b/Python/random.c
index 3f307cf..af3d0bd 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -67,7 +67,11 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
return 0;
}
-#elif HAVE_GETENTROPY
+/* Issue #25003: Don' use getentropy() on Solaris (available since
+ * Solaris 11.3), it is blocking whereas os.urandom() should not block. */
+#elif defined(HAVE_GETENTROPY) && !defined(sun)
+#define PY_GETENTROPY 1
+
/* Fill buffer with size pseudo-random bytes generated by getentropy().
Return 0 on success, or raise an exception and return -1 on error.
@@ -275,7 +279,7 @@ _PyOS_URandom(void *buffer, Py_ssize_t size)
#ifdef MS_WINDOWS
return win32_urandom((unsigned char *)buffer, size, 1);
-#elif HAVE_GETENTROPY
+#elif defined(PY_GETENTROPY)
return py_getentropy(buffer, size, 0);
#else
return dev_urandom_python((char*)buffer, size);
@@ -322,7 +326,7 @@ _PyRandom_Init(void)
else {
#ifdef MS_WINDOWS
(void)win32_urandom(secret, secret_size, 0);
-#elif HAVE_GETENTROPY
+#elif defined(PY_GETENTROPY)
(void)py_getentropy(secret, secret_size, 1);
#else
dev_urandom_noraise(secret, secret_size);
@@ -338,7 +342,7 @@ _PyRandom_Fini(void)
CryptReleaseContext(hCryptProv, 0);
hCryptProv = 0;
}
-#elif HAVE_GETENTROPY
+#elif defined(PY_GETENTROPY)
/* nothing to clean */
#else
dev_urandom_close();