MantisBT - CMake
View Issue Details
0014390CMakeCMakepublic2013-09-05 03:562016-06-10 14:31
Magnus Johansson 
Kitware Robot 
normalcrashalways
closedmoved 
CMake 2.8.11.1 
 
0014390: CMake crashes on infinite recursion
I 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.
Just run the snippet above.
May be the same issue as 0013822, but I know too little about cmake internals to be certain.
No tags attached.
Issue History
2013-09-05 03:56Magnus JohanssonNew Issue
2013-09-05 07:35David ColeNote Added: 0033785
2013-09-05 07:57Magnus JohanssonNote Added: 0033786
2013-09-05 08:46David ColeNote Added: 0033787
2013-09-05 09:27Magnus JohanssonNote Added: 0033788
2013-09-05 13:27David ColeNote Added: 0033789
2016-06-10 14:29Kitware RobotNote Added: 0042360
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0033785)
David Cole   
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   
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   
2013-09-05 08:45   
What's a reasonable limit?
(0033788)
Magnus Johansson   
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   
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   
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.