From 197f5fb1df74de24a0145b4cc16bbdbb280f9835 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 12 Aug 2019 05:40:22 -0400 Subject: [PATCH] Add ASSERT to check m_fd for values <0 We are seeing RNG falures on HURD, but we are not throwing when constructing BlockingRng or NonblockingRng. This is despite the fact that /dev/urandom is missing during testing. NonblockingRng should always thwo when /dev/urandom is missing. --- osrng.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osrng.cpp b/osrng.cpp index 5d9b9b12..2e846b45 100644 --- a/osrng.cpp +++ b/osrng.cpp @@ -134,6 +134,9 @@ NonblockingRng::NonblockingRng() m_fd = open("/dev/urandom",O_RDONLY); if (m_fd == -1) throw OS_RNG_Err("open /dev/urandom"); + + // Do some OSes return -NNN instead of -1? + CRYPTOPP_ASSERT(m_fd >= 0); #endif } @@ -203,6 +206,9 @@ BlockingRng::BlockingRng() m_fd = open(CRYPTOPP_BLOCKING_RNG_FILENAME,O_RDONLY); if (m_fd == -1) throw OS_RNG_Err("open " CRYPTOPP_BLOCKING_RNG_FILENAME); + + // Do some OSes return -NNN instead of -1? + CRYPTOPP_ASSERT(m_fd >= 0); } BlockingRng::~BlockingRng()