View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014390CMakeCMakepublic2013-09-05 03:562016-06-10 14:31
ReporterMagnus Johansson 
Assigned ToKitware Robot 
PrioritynormalSeveritycrashReproducibilityalways
StatusclosedResolutionmoved 
PlatformOSOS Version
Product VersionCMake 2.8.11.1 
Target VersionFixed in Version 
Summary0014390: CMake crashes on infinite recursion
DescriptionI accidentally (hurried through a query replace) wrote something like this:

cmake_minimum_required(VERSION 2.8)

function(blah)
     blah()
endfunction(blah)

blah()

This makes cmake segfault, likely due to exhausted stack.
Steps To ReproduceJust run the snippet above.
Additional InformationMay be the same issue as 0013822, but I know too little about cmake internals to be certain.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0033785)
David Cole (manager)
2013-09-05 07:35

A C program would also crash when called in such a manner...

How is this a CMake bug?

If you are writing a function, it's up to you to make sure any recursion is not infinite...
(0033786)
Magnus Johansson (reporter)
2013-09-05 07:57

CMake could detect this similarily to 0013822, and give a more descriptive error than "segmentation fault". This mistake was a pain to find in project with more than 150 CMakeLists.txt files.

From a note on 0013822:
"CMake should track the call stack depth and limit it so that this case fails with an error instead of crashing."
(0033787)
David Cole (manager)
2013-09-05 08:45

What's a reasonable limit?
(0033788)
Magnus Johansson (reporter)
2013-09-05 09:27

I have yet to see a case where a recursive cmake function is necessary. But then again, I've so far only used cmake in one project. For our purposes, no recursion at all is sufficient. I'm not experienced enough with cmake to have an idea of a reasonable limit in general.
(0033789)
David Cole (manager)
2013-09-05 13:27

This cmake -P script:

    function(intentionally_recurse_for_no_reason level)
      message("level='${level}'")
      math(EXPR level "${level} + 1")
      intentionally_recurse_for_no_reason(${level})
    endfunction()

    intentionally_recurse_for_no_reason(0)

...runs for 17,393 iterations using CMake 2.8.12-rc1 before it crashes.

If CMake developers were to do anything to address this bug, perhaps it should be by detecting the depth of the function call stack, and giving some sort of warning, or perhaps even an error, if it exceeds some limit between 5,000 and 15,000.

The problem is this:

If the chosen limit is too small, it may be hit in normal processing. If it's too high, then CMake will crash anyway on platforms where the stack is not as big as it is in my one test case here.
(0042360)
Kitware Robot (administrator)
2016-06-10 14:29

Resolving issue as `moved`.

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
2013-09-05 03:56 Magnus Johansson New Issue
2013-09-05 07:35 David Cole Note Added: 0033785
2013-09-05 07:57 Magnus Johansson Note Added: 0033786
2013-09-05 08:46 David Cole Note Added: 0033787
2013-09-05 09:27 Magnus Johansson Note Added: 0033788
2013-09-05 13:27 David Cole Note Added: 0033789
2016-06-10 14:29 Kitware Robot Note Added: 0042360
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team