summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2017-01-06 22:22:14 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2017-01-06 22:22:14 +0900
commite2dc0902bb379986835f119828b86dc0100bafaa (patch)
tree96bdb868edb33a0e3e73c808d5cdc0968cf2d9ca
parent5d2742da154b388d69b59bf28716c4c3c8970646 (diff)
Fix assertion failure in SimpleRandomizer::getRandomBytes
errno might not be initialized to 0, and we may get both rv == -1 and errno != ENOSYS. This leads to assertion failure. Since getrandom_linux always returns -1 on failure, checking errno is useless in this function.
-rw-r--r--src/SimpleRandomizer.cc13
1 files changed, 1 insertions, 12 deletions
diff --git a/src/SimpleRandomizer.cc b/src/SimpleRandomizer.cc
index ca859f5a..5311ba6b 100644
--- a/src/SimpleRandomizer.cc
+++ b/src/SimpleRandomizer.cc
@@ -101,18 +101,7 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len)
static bool have_random_support = true;
if (have_random_support) {
auto rv = getrandom_linux(buf, len);
- if (rv != -1
-#ifdef ENOSYS
- /* If the system does not know ENOSYS at this point, just leave the
- * check out. If the call failed, we'll not take this branch at all
- * and disable support below.
- */
- || errno != ENOSYS
-#endif
- ) {
- if (rv < -1) {
- A2_LOG_ERROR(fmt("Failed to produce randomness: %d", errno));
- }
+ if (rv != -1) {
// getrandom is not supposed to fail, ever, so, we want to assert here.
assert(rv >= 0 && (size_t)rv == len);
return;