Commit 97d6e4c6 authored by Victor Stinner's avatar Victor Stinner

Issue #23707: On UNIX, os.urandom() now calls the Python signal handler when

read() is interrupted by a signal.

dev_urandom_python() now calls _Py_read() helper instead of calling directly
read().
parent 0148ef09
...@@ -262,29 +262,21 @@ dev_urandom_python(char *buffer, Py_ssize_t size) ...@@ -262,29 +262,21 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
} }
} }
Py_BEGIN_ALLOW_THREADS
do { do {
do { n = _Py_read(fd, buffer, (size_t)size);
n = read(fd, buffer, (size_t)size); if (n == -1)
} while (n < 0 && errno == EINTR); return -1;
if (n <= 0) if (n == 0) {
break; PyErr_Format(PyExc_RuntimeError,
"Failed to read %zi bytes from /dev/urandom",
size);
return -1;
}
buffer += n; buffer += n;
size -= (Py_ssize_t)n; size -= n;
} while (0 < size); } while (0 < size);
Py_END_ALLOW_THREADS
if (n <= 0)
{
/* stop on error or if read(size) returned 0 */
if (n < 0)
PyErr_SetFromErrno(PyExc_OSError);
else
PyErr_Format(PyExc_RuntimeError,
"Failed to read %zi bytes from /dev/urandom",
size);
return -1;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment