diff options
author | Thomas Devoogdt <thomas@devoogdt.com> | 2023-04-10 19:58:15 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-04-11 13:56:12 +0200 |
commit | cb57abb46f06f4ede8d9ccbdaac67377fdf416cf (patch) | |
tree | 93d512ffcce80d1269dd8be538caeeb1fd5561cc | |
parent | 200a9669fbf6f06894e4243cccc9fc11a1a6073a (diff) | |
download | busybox-w32-cb57abb46f06f4ede8d9ccbdaac67377fdf416cf.tar.gz busybox-w32-cb57abb46f06f4ede8d9ccbdaac67377fdf416cf.tar.bz2 busybox-w32-cb57abb46f06f4ede8d9ccbdaac67377fdf416cf.zip |
seedrng: fix for glibc <= 2.24 not providing random header
- dropped the wrong define (not sure why it was there)
- <sys/random.h> not available if glibc <= 2.24
- GRND_NONBLOCK not defined if <sys/random.h> not included
- ret < 0 && errno == ENOSYS has to be true to get creditable set
Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/seedrng.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c index 7cc855141..3bf6e2ea7 100644 --- a/miscutils/seedrng.c +++ b/miscutils/seedrng.c | |||
@@ -42,25 +42,31 @@ | |||
42 | #include "libbb.h" | 42 | #include "libbb.h" |
43 | 43 | ||
44 | #include <linux/random.h> | 44 | #include <linux/random.h> |
45 | #include <sys/random.h> | ||
46 | #include <sys/file.h> | 45 | #include <sys/file.h> |
47 | 46 | ||
48 | /* Fix up glibc <= 2.24 not having getrandom() */ | 47 | /* Fix up glibc <= 2.24 not having getrandom() */ |
49 | #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 24 | 48 | #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 24 |
50 | #include <sys/syscall.h> | 49 | #include <sys/syscall.h> |
51 | # define getrandom(...) bb_getrandom(__VA_ARGS__) | ||
52 | static ssize_t getrandom(void *buffer, size_t length, unsigned flags) | 50 | static ssize_t getrandom(void *buffer, size_t length, unsigned flags) |
53 | { | 51 | { |
54 | # if defined(__NR_getrandom) | 52 | # if defined(__NR_getrandom) |
55 | return syscall(__NR_getrandom, buffer, length, flags); | 53 | return syscall(__NR_getrandom, buffer, length, flags); |
56 | # else | 54 | # else |
57 | return ENOSYS; | 55 | errno = ENOSYS; |
56 | return -1; | ||
58 | # endif | 57 | # endif |
59 | } | 58 | } |
59 | #else | ||
60 | #include <sys/random.h> | ||
61 | #endif | ||
62 | |||
63 | /* Apparently some headers don't ship with this yet. */ | ||
64 | #ifndef GRND_NONBLOCK | ||
65 | #define GRND_NONBLOCK 0x0001 | ||
60 | #endif | 66 | #endif |
61 | 67 | ||
62 | #ifndef GRND_INSECURE | 68 | #ifndef GRND_INSECURE |
63 | #define GRND_INSECURE 0x0004 /* Apparently some headers don't ship with this yet. */ | 69 | #define GRND_INSECURE 0x0004 |
64 | #endif | 70 | #endif |
65 | 71 | ||
66 | #define DEFAULT_SEED_DIR "/var/lib/seedrng" | 72 | #define DEFAULT_SEED_DIR "/var/lib/seedrng" |