cpython: d3e8db93dc18 (original) (raw)

Mercurial > cpython

changeset 90460:d3e8db93dc18

Issue #21207: Detect when the os.urandom cached fd has been closed or replaced, and open it anew. [#21207]

Antoine Pitrou solipsis@pitrou.net
date Sat, 26 Apr 2014 14:35:19 +0200
parents 9fc4a1ebe652(current diff)a66524ce9551(diff)
children 9ab6d13553ef
files Misc/NEWS
diffstat 3 files changed, 85 insertions(+), 10 deletions(-)[+] [-] Lib/test/test_os.py 43 Misc/NEWS 3 Python/random.c 49

line wrap: on

line diff

--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1070,6 +1070,49 @@ class URandomTests(unittest.TestCase): """ assert_python_ok('-c', code)

+

+ @contextlib.contextmanager def _execvpe_mockup(defpath=None):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -57,6 +57,9 @@ Core and Builtins Library ------- +- Issue #21207: Detect when the os.urandom cached fd has been closed or

--- a/Python/random.c +++ b/Python/random.c @@ -3,6 +3,9 @@ #include <windows.h> #else #include <fcntl.h> +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif #endif #ifdef Py_DEBUG @@ -69,7 +72,11 @@ win32_urandom(unsigned char *buffer, Py_ #ifndef MS_WINDOWS -static int urandom_fd = -1; +static struct {

+} urandom_cache = { -1 }; /* Read size bytes from /dev/urandom into buffer. Call Py_FatalError() on error. */ @@ -109,12 +116,24 @@ dev_urandom_python(char *buffer, Py_ssiz { int fd; Py_ssize_t n;

if (size <= 0) return 0;

@@ -129,14 +148,24 @@ dev_urandom_python(char *buffer, Py_ssiz PyErr_SetFromErrno(PyExc_OSError); return -1; }