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.
pull/877/head
Jeffrey Walton 2019-08-12 05:40:22 -04:00
parent 6028587b9f
commit 197f5fb1df
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 6 additions and 0 deletions

View File

@ -134,6 +134,9 @@ NonblockingRng::NonblockingRng()
m_fd = open("/dev/urandom",O_RDONLY); m_fd = open("/dev/urandom",O_RDONLY);
if (m_fd == -1) if (m_fd == -1)
throw OS_RNG_Err("open /dev/urandom"); throw OS_RNG_Err("open /dev/urandom");
// Do some OSes return -NNN instead of -1?
CRYPTOPP_ASSERT(m_fd >= 0);
#endif #endif
} }
@ -203,6 +206,9 @@ BlockingRng::BlockingRng()
m_fd = open(CRYPTOPP_BLOCKING_RNG_FILENAME,O_RDONLY); m_fd = open(CRYPTOPP_BLOCKING_RNG_FILENAME,O_RDONLY);
if (m_fd == -1) if (m_fd == -1)
throw OS_RNG_Err("open " CRYPTOPP_BLOCKING_RNG_FILENAME); throw OS_RNG_Err("open " CRYPTOPP_BLOCKING_RNG_FILENAME);
// Do some OSes return -NNN instead of -1?
CRYPTOPP_ASSERT(m_fd >= 0);
} }
BlockingRng::~BlockingRng() BlockingRng::~BlockingRng()