diff options
author | Mike Gilbert <floppym@gentoo.org> | 2021-12-24 19:20:36 -0500 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-12-26 10:13:56 +0900 |
commit | 289b41aae7356b7a6c72ff4a3476193a084ff33f (patch) | |
tree | b041059ee295d379bb72e7144dc72edd64705a07 /src/basic/random-util.c | |
parent | 4b7b73c7140b3c923064c6bf27a30b0e88a72f7a (diff) | |
download | systemd-289b41aae7356b7a6c72ff4a3476193a084ff33f.tar.gz |
random-util: use ssize_t for getrandom return value
This matches the prototype provided by glibc.
Diffstat (limited to 'src/basic/random-util.c')
-rw-r--r-- | src/basic/random-util.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/basic/random-util.c b/src/basic/random-util.c index c2be962355..e117330857 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -161,7 +161,6 @@ int genuine_random_bytes(void *p, size_t n, RandomFlags flags) { static int have_syscall = -1; _cleanup_close_ int fd = -1; bool got_some = false; - int r; /* Gathers some high-quality randomness from the kernel (or potentially mid-quality randomness from * the CPU if the RANDOM_ALLOW_RDRAND flag is set). This call won't block, unless the RANDOM_BLOCK @@ -220,18 +219,19 @@ int genuine_random_bytes(void *p, size_t n, RandomFlags flags) { if (have_syscall != 0 && !HAS_FEATURE_MEMORY_SANITIZER) { for (;;) { - r = getrandom(p, n, + ssize_t l; + l = getrandom(p, n, (FLAGS_SET(flags, RANDOM_BLOCK) ? 0 : GRND_NONBLOCK) | (FLAGS_SET(flags, RANDOM_ALLOW_INSECURE) ? GRND_INSECURE : 0)); - if (r > 0) { + if (l > 0) { have_syscall = true; - if ((size_t) r == n) + if ((size_t) l == n) return 0; /* Yay, success! */ - assert((size_t) r < n); - p = (uint8_t*) p + r; - n -= r; + assert((size_t) l < n); + p = (uint8_t*) p + l; + n -= l; if (FLAGS_SET(flags, RANDOM_EXTEND_WITH_PSEUDO)) { /* Fill in the remaining bytes using pseudo-random values */ @@ -248,7 +248,7 @@ int genuine_random_bytes(void *p, size_t n, RandomFlags flags) { /* Fill in the rest with /dev/urandom */ break; - } else if (r == 0) { + } else if (l == 0) { have_syscall = true; return -EIO; |