[cmake-developers] [CMake 0015976]: cmSystemTools::RandomSeed() requests excessive entropy per invocation
Mantis Bug Tracker
mantis at public.kitware.com
Tue Feb 16 20:26:26 EST 2016
The following issue has been SUBMITTED.
======================================================================
https://cmake.org/Bug/view.php?id=15976
======================================================================
Reported By: Cristian Rodríguez
Assigned To:
======================================================================
Project: CMake
Issue ID: 15976
Category: CMake
Reproducibility: always
Severity: minor
Priority: normal
Status: new
======================================================================
Date Submitted: 2016-02-16 20:26 EST
Last Modified: 2016-02-16 20:26 EST
======================================================================
Summary: cmSystemTools::RandomSeed() requests excessive
entropy per invocation
Description:
cmSystemTools::RandomSeed() opens a *buffered* ifstream, the final result is
that each invocation requests _IO_BUFSIZ -1 of entropy to the operating system
instead of just sizeof(seed)
Steps to Reproduce:
mkdir test_cmake
echo "PROJECT(foo)" > CMakeLists.txt
cd test_cmake
strace -f -ocmake.trace cmake .
open cmake.trace
10768 26289 open("/dev/urandom", O_RDONLY) = 4
10769 26289 read(4,
"h\304j\vx\314\26\0042\250g\275\0014,\256\251\257T&\304\212\310\347q\201\263\324\330\273z8"...,
8191) = 8191
10770 26289 close(4) = 0
10771 26289 write(3, "cmake_minimum_required(VERSION 3"..., 795) = 795
10772 26289 close(3) = 0
10773 26289 stat("/home/crrodriguez/test_cmake/CMakeFiles/CMakeTmp",
{st_mode=S_IFDIR|0755, st_size=58, ...}) = 0
10774 26289 getcwd("/home/crrodriguez/test_cmake", 2048) = 29
Additional Information:
git diff
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 3ba7287..26bec34 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2184,8 +2184,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);
+ fin.open("/dev/urandom");
+ if(fin.good() && fin.read(seed.bytes, sizeof(seed)) &&
fin.gcount() == sizeof(seed))
{
return seed.integer;
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2016-02-16 20:26 Cristian RodríguezNew Issue
======================================================================
More information about the cmake-developers
mailing list