View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015976CMakeCMakepublic2016-02-16 20:262016-06-10 14:21
ReporterCristian Rodríguez 
Assigned ToBrad King 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformlinuxOSlinuxOS Versionany
Product VersionCMake 3.4.3 
Target VersionCMake 3.6Fixed in VersionCMake 3.6 
Summary0015976: cmSystemTools::RandomSeed() requests excessive entropy per invocation
DescriptioncmSystemTools::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 Reproducemkdir 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 Informationgit 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;
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0040496)
Brad King (manager)
2016-02-17 09:05
edited on: 2016-02-19 09:45

Good catch, thanks! Applied:

 cmSystemTools: Avoid excess entropy consumption by RandomSeed
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f23f18ab [^]

(0041244)
Kitware Robot (administrator)
2016-06-10 14:21

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2016-02-16 20:26 Cristian Rodríguez New Issue
2016-02-17 09:05 Brad King Note Added: 0040496
2016-02-17 09:05 Brad King Assigned To => Brad King
2016-02-17 09:05 Brad King Status new => resolved
2016-02-17 09:05 Brad King Resolution open => fixed
2016-02-17 09:05 Brad King Fixed in Version => CMake 3.6
2016-02-17 09:05 Brad King Target Version => CMake 3.6
2016-02-19 09:45 Brad King Note Edited: 0040496
2016-06-10 14:21 Kitware Robot Note Added: 0041244
2016-06-10 14:21 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team