diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-12-30 21:25:24 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-12-31 08:54:41 +0100 |
commit | 33e8e95cbd0d6724553f390142d4b11352d59dd0 (patch) | |
tree | 62f19fa9400d3dd952525fefa09c56703d06ec4f /sysdeps | |
parent | 4dfa8f4870c862540bd9b09130a68664d45f1569 (diff) | |
download | glibc-33e8e95cbd0d6724553f390142d4b11352d59dd0.tar.gz glibc-33e8e95cbd0d6724553f390142d4b11352d59dd0.tar.xz glibc-33e8e95cbd0d6724553f390142d4b11352d59dd0.zip |
hurd: Make getrandom a stub inside the random translator
glibc uses /dev/urandom for getrandom(), and from version 2.34 malloc initialization uses it. We have to detect when we are running the random translator itself, in which case we can't read ourself.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/mach/hurd/getrandom.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sysdeps/mach/hurd/getrandom.c b/sysdeps/mach/hurd/getrandom.c index 645f2930b7..24f9ac60f7 100644 --- a/sysdeps/mach/hurd/getrandom.c +++ b/sysdeps/mach/hurd/getrandom.c @@ -21,6 +21,8 @@ #include <unistd.h> #include <not-cancel.h> +extern char *trivfs_server_name __attribute__((weak)); + /* Write up to LENGTH bytes of randomness starting at BUFFER. Return the number of bytes written, or -1 on error. */ ssize_t @@ -31,6 +33,17 @@ __getrandom (void *buffer, size_t length, unsigned int flags) size_t amount_read; int fd; + if (&trivfs_server_name && trivfs_server_name + && trivfs_server_name[0] == 'r' + && trivfs_server_name[1] == 'a' + && trivfs_server_name[2] == 'n' + && trivfs_server_name[3] == 'd' + && trivfs_server_name[4] == 'o' + && trivfs_server_name[5] == 'm' + && trivfs_server_name[6] == '\0') + /* We are random, don't try to read ourselves! */ + return length; + if (flags & GRND_RANDOM) random_source = "/dev/random"; |