mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-18 13:10:17 -06:00
cmSystemTools: Avoid excess entropy consumption by RandomSeed (#15976)
Read `/dev/urandom` without buffering to avoid taking more than we need.
This commit is contained in:
committed by
Brad King
parent
b13a74b35b
commit
f23f18ab68
@@ -2183,8 +2183,10 @@ unsigned int cmSystemTools::RandomSeed()
|
|||||||
} seed;
|
} seed;
|
||||||
|
|
||||||
// Try using a real random source.
|
// Try using a real random source.
|
||||||
cmsys::ifstream fin("/dev/urandom");
|
cmsys::ifstream fin;
|
||||||
if(fin && fin.read(seed.bytes, sizeof(seed)) &&
|
fin.rdbuf()->pubsetbuf(0, 0); // Unbuffered read.
|
||||||
|
fin.open("/dev/urandom");
|
||||||
|
if(fin.good() && fin.read(seed.bytes, sizeof(seed)) &&
|
||||||
fin.gcount() == sizeof(seed))
|
fin.gcount() == sizeof(seed))
|
||||||
{
|
{
|
||||||
return seed.integer;
|
return seed.integer;
|
||||||
|
|||||||
Reference in New Issue
Block a user