summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorCristian Rodríguez <crrodriguez@opensuse.org>2016-02-17 14:02:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-02-19 14:44:59 (GMT)
commitf23f18ab686faa0ce91486143469bb58753b0843 (patch)
tree3400e6e9c38721e7825605834ab178dfcfeabc1e /Source/cmSystemTools.cxx
parentb13a74b35b17ecb44ec6ff552ecb1cbdac204361 (diff)
downloadCMake-f23f18ab686faa0ce91486143469bb58753b0843.zip
CMake-f23f18ab686faa0ce91486143469bb58753b0843.tar.gz
CMake-f23f18ab686faa0ce91486143469bb58753b0843.tar.bz2
cmSystemTools: Avoid excess entropy consumption by RandomSeed (#15976)
Read `/dev/urandom` without buffering to avoid taking more than we need.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx6
1 files changed, 4 insertions, 2 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index c9670fa..9af54bf 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -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;