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:
parent
b13a74b35b
commit
f23f18ab68
|
@ -2183,8 +2183,10 @@ unsigned int cmSystemTools::RandomSeed()
|
|||
} seed;
|
||||
|
||||
// Try using a real random source.
|
||||
cmsys::ifstream fin("/dev/urandom");
|
||||
if(fin && fin.read(seed.bytes, sizeof(seed)) &&
|
||||
cmsys::ifstream fin;
|
||||
fin.rdbuf()->pubsetbuf(0, 0); // Unbuffered read.
|
||||
fin.open("/dev/urandom");
|
||||
if(fin.good() && fin.read(seed.bytes, sizeof(seed)) &&
|
||||
fin.gcount() == sizeof(seed))
|
||||
{
|
||||
return seed.integer;
|
||||
|
|
Loading…
Reference in New Issue