MantisBT - CMake
View Issue Details
0015367CMakeCMakepublic2015-01-22 23:042015-07-08 08:57
Thomas Klausner 
Brad King 
highcrashsometimes
closedfixed 
amd64NetBSD7.99.4
CMake 3.1 
CMake 3.1.2CMake 3.1.2 
0015367: cmake crash in GetNumberOfFilesInDirectory
In Source/kwsys/Directory.cxx, the result value of opendir() is not checked, which can lead to readdir being called with a NULL pointer as first argument, which, at least on NetBSD, leads to a segfault.
I don't know how to cause this, but it happened to me in parallel builds on a tmpfs e.g. when building wesnoth.
The attached patch returns '0' as count for directories when opendir fails, which makes wesnoth build for me. Perhaps dirp==NULL should be reported, but I don't know how to best do that, so I'll leave that up to you.
No tags attached.
cxx patch-Source_kwsys_Directory.cxx (491) 2015-01-22 23:04
https://public.kitware.com/Bug/file/5356/patch-Source_kwsys_Directory.cxx
Issue History
2015-01-22 23:04Thomas KlausnerNew Issue
2015-01-22 23:04Thomas KlausnerFile Added: patch-Source_kwsys_Directory.cxx
2015-01-23 13:17Brad KingNote Added: 0037788
2015-01-26 10:27Brad KingNote Added: 0037811
2015-01-26 10:27Brad KingAssigned To => Brad King
2015-01-26 10:27Brad KingStatusnew => resolved
2015-01-26 10:27Brad KingResolutionopen => fixed
2015-01-26 10:27Brad KingFixed in Version => CMake 3.2
2015-01-26 10:27Brad KingTarget Version => CMake 3.2
2015-02-05 09:24Brad KingNote Added: 0037923
2015-02-05 09:24Brad KingFixed in VersionCMake 3.2 => CMake 3.1.2
2015-02-05 09:24Brad KingTarget VersionCMake 3.2 => CMake 3.1.2
2015-07-08 08:57Robert MaynardNote Added: 0039040
2015-07-08 08:57Robert MaynardStatusresolved => closed

Notes
(0037788)
Brad King   
2015-01-23 13:17   
Thanks. I've applied a fix in KWSys upstream and submitted for testing here:

 http://review.source.kitware.com/18941 [^]

Once merged there it can be integrated into CMake too.
(0037811)
Brad King   
2015-01-26 10:27   
This has now been integrated in upstream KWSys and ported to CMake:

 KWSys Directory: Check opendir return value before using it
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=482c8475 [^]
(0037923)
Brad King   
2015-02-05 09:24   
I merged this fix into the 'release' branch for 3.1.2.
(0039040)
Robert Maynard   
2015-07-08 08:57   
Closing resolved issues that have not been updated in more than 4 months.