mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
Issue #22181: The availability of the getrandom() is now checked in configure,
and stored in pyconfig.h as the new HAVE_GETRANDOM_SYSCALL define. Fix os.urandom() tests using file descriptors if os.urandom() uses getrandom().
This commit is contained in:
parent
79d68f929d
commit
9eb57c5fa5
5 changed files with 73 additions and 140 deletions
|
@ -6,11 +6,8 @@
|
|||
# ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
# endif
|
||||
# ifdef HAVE_SYS_SYSCALL_H
|
||||
# ifdef HAVE_GETRANDOM_SYSCALL
|
||||
# include <sys/syscall.h>
|
||||
# if defined(__linux__) && defined(SYS_getrandom)
|
||||
# define HAVE_GETRANDOM
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
@ -102,7 +99,7 @@ py_getentropy(unsigned char *buffer, Py_ssize_t size, int fatal)
|
|||
|
||||
#else /* !HAVE_GETENTROPY */
|
||||
|
||||
#ifdef HAVE_GETRANDOM
|
||||
#ifdef HAVE_GETRANDOM_SYSCALL
|
||||
static int
|
||||
py_getrandom(void *buffer, Py_ssize_t size, int raise)
|
||||
{
|
||||
|
@ -173,7 +170,7 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
|
|||
if (fd < 0)
|
||||
Py_FatalError("Failed to open /dev/urandom");
|
||||
|
||||
#ifdef HAVE_GETRANDOM
|
||||
#ifdef HAVE_GETRANDOM_SYSCALL
|
||||
if (py_getrandom(buffer, size, 0) == 1)
|
||||
return;
|
||||
/* getrandom() is not supported by the running kernel, fall back
|
||||
|
@ -205,14 +202,14 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
|
|||
int fd;
|
||||
Py_ssize_t n;
|
||||
struct _Py_stat_struct st;
|
||||
#ifdef HAVE_GETRANDOM
|
||||
#ifdef HAVE_GETRANDOM_SYSCALL
|
||||
int res;
|
||||
#endif
|
||||
|
||||
if (size <= 0)
|
||||
return 0;
|
||||
|
||||
#ifdef HAVE_GETRANDOM
|
||||
#ifdef HAVE_GETRANDOM_SYSCALL
|
||||
res = py_getrandom(buffer, size, 1);
|
||||
if (res < 0)
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue