MantisBT - CMake
View Issue Details
0016044CMakeCMakepublic2016-04-01 05:572016-06-10 14:21
Gianfranco 
Brad King 
highcrashhave not tried
closedfixed 
LinuxUbuntu16.04
CMake 3.5.1 
CMake 3.5.2CMake 3.5.2 
0016044: cmake crashed with SIGSEGV in cmTarget::GetProperty()
https://bugs.launchpad.net/ubuntu/+source/cmake/+bug/1564741 [^]

As reported on the Ubuntu bug, the culprit seems to be commit a67231ac114235f0af4673235c4c07fa896c8ab6.
patch
has duplicate 0016048closed  Segfault on target_link_libraries() with aliased target from another subdirectory 
patch 0001-Prevent-SIGSEGV-when-ALIASing-a-target-defined-in-an.patch (14,036) 2016-04-01 08:30
https://public.kitware.com/Bug/file/5664/0001-Prevent-SIGSEGV-when-ALIASing-a-target-defined-in-an.patch
Issue History
2016-04-01 05:57GianfrancoNew Issue
2016-04-01 05:57GianfrancoNote Added: 0040787
2016-04-01 08:30Matteo SettenviniFile Added: 0001-Prevent-SIGSEGV-when-ALIASing-a-target-defined-in-an.patch
2016-04-01 08:31Matteo SettenviniNote Added: 0040788
2016-04-01 08:31Matteo SettenviniTag Attached: patch
2016-04-01 09:44Brad KingNote Added: 0040790
2016-04-01 09:44Brad KingAssigned To => Brad King
2016-04-01 09:44Brad KingStatusnew => resolved
2016-04-01 09:44Brad KingResolutionopen => fixed
2016-04-01 09:44Brad KingFixed in Version => CMake 3.5.2
2016-04-01 09:44Brad KingTarget Version => CMake 3.5.2
2016-04-01 10:01Matteo SettenviniNote Added: 0040792
2016-04-01 10:07Brad KingStatusresolved => assigned
2016-04-01 10:07Brad KingResolutionfixed => reopened
2016-04-01 10:07Brad KingFixed in VersionCMake 3.5.2 =>
2016-04-01 10:08Brad KingNote Added: 0040794
2016-04-01 10:23Matteo SettenviniNote Added: 0040795
2016-04-01 10:41Brad KingNote Added: 0040796
2016-04-01 10:43Brad KingStatusassigned => resolved
2016-04-01 10:43Brad KingResolutionreopened => fixed
2016-04-01 10:43Brad KingFixed in Version => CMake 3.5.2
2016-04-01 15:30Brad KingRelationship addedhas duplicate 0016048
2016-04-01 15:46Brad KingNote Added: 0040800
2016-04-04 03:19Matteo SettenviniNote Added: 0040801
2016-06-10 14:21Kitware RobotNote Added: 0041203
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040787)
Gianfranco   
2016-04-01 05:57   
cmTarget::GetProperty(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cmMakefile*) const ()
 cmGetTargetPropertyCommand::InitialPass(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, cmExecutionStatus&) ()
 cmMakefile::ExecuteCommand(cmListFileFunction const&, cmExecutionStatus&) ()
 cmForEachFunctionBlocker::IsFunctionBlocked(cmListFileFunction const&, cmMakefile&, cmExecutionStatus&) ()
 cmMakefile::IsFunctionBlocked(cmListFileFunction const&, cmExecutionStatus&) ()
Title: cmake crashed with SIGSEGV in cmTarget::GetProperty()
(0040788)
Matteo Settenvini   
2016-04-01 08:31   
Hallo, I am the original reporter. Attached is a patch fixing the problem for me. It includes a test case.
(0040790)
Brad King   
2016-04-01 09:44   
Re 0016044:0040788: Thanks for tracking it down! This should fix it:

 Fix lookup of an ALIAS target outside aliased target's directory
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=275a7c26 [^]

I included your test case too.

I've queued this for merge to 'release' for inclusion in 3.5.2.
(0040792)
Matteo Settenvini   
2016-04-01 10:01   
Thanks Brad, that was quick!

I am afraid though that it is still not enough. I am having another segfault with your commit at the end of the configuration process, that I do not have with mine.

It is due to the implementation of:
cmLocalGenerator::FindGeneratorTarget(const std::string& name) const

On return, it does not check if an alias is really present before dereferencing the iterator.

You can take a fix directly from my patch, which saves some lines of code too :-).

Cheers!
(0040794)
Brad King   
2016-04-01 10:08   
Re 0016044:0040792: Thanks for testing it. Can you provide a test case for that crash too?
(0040795)
Matteo Settenvini   
2016-04-01 10:23   
Not yet, although not for wont of trying. We have a big project with ~7'000 cmake code lines, which definitely triggers this, but I've been unable to boil it down to a simple use case.

However, it does definitely breaks all our builds, so we're already patching CMake on our side. The fix should be relatively harmless, though, as one can see that FindGeneratorTarget potentially dereferences an invalid iterator.

I'll try to come up with something, but it was escalated to a low priority task on my side, so it might take some time.
(0040796)
Brad King   
2016-04-01 10:41   
Re 0016044:0040795: Okay, thanks. We can add the generate-step test case later when you produce it.

I've revised the fix:

 Fix lookup of an ALIAS target outside aliased target's directory
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e1eae2a3 [^]

Then I followed it up with another commit to help avoid re-introducing the incorrect alias lookup later:

 Rename local target lookup methods to clarify purpose
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e47ec3c9 [^]
(0040800)
Brad King   
2016-04-01 15:46   
Thanks to a second report of this issue in 0016048 with another test case I was able to improve the test case to cover the cmLocalGenerator part of this fix too. Here is a revised fix:

 Fix lookup of an ALIAS target outside aliased target's directory
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bc30f8b5 [^]

 Rename local target lookup methods to clarify purpose
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0e44f489 [^]
(0040801)
Matteo Settenvini   
2016-04-04 03:19   
Thanks again Brad, the last commits you posted fix the problem for me.
(0041203)
Kitware Robot   
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.