[cmake-developers] [CMake 0015572]: Crash when parsing malformed foreach() inside function()

Mantis Bug Tracker mantis at public.kitware.com
Mon May 18 08:16:27 EDT 2015


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=15572 
====================================================================== 
Reported By:                Daniel Vrátil
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15572
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2015-05-18 08:16 EDT
Last Modified:              2015-05-18 08:16 EDT
====================================================================== 
Summary:                    Crash when parsing malformed foreach() inside
function()
Description: 
When parsing a malformed CMake script with foreach() inside function(), where
the foreach() is not correctly terminated (missing endforeach()), CMake crashes
instead of printing an error message.

Steps to Reproduce: 
Run following script with cmake -P

    function(printLists)
        foreach(i ITEMS 1)
            message(STATUS "Item: ${i}")
    endfunction()
    printLists()

CMake crashes:
cmake: /builddir/build/BUILD/cmake-3.2.2/Source/cmMakefile.cxx:3328: void
cmMakefile::PopLoopBlockBarrier(): Assertion `this->LoopBlockCounter.top() == 0'
failed.

http://public.kitware.com/Bug/view.php?id=0  0x00007ffff642ba98 in __GI_raise
(sig=sig at entry=6) at ../sysdeps/unix/sysv/linux/raise.c:55
http://public.kitware.com/Bug/view.php?id=1  0x00007ffff642d72a in __GI_abort ()
at abort.c:89
http://public.kitware.com/Bug/view.php?id=2  0x00007ffff6424247 in
__assert_fail_base (fmt=<optimized out>, assertion=assertion at entry=0x769710
"this->LoopBlockCounter.top() == 0", file=file at entry=0x769690
"/builddir/build/BUILD/cmake-3.2.2/Source/cmMakefile.cxx", 
    line=line at entry=3328, function=function at entry=0x76abe0
<cmMakefile::PopLoopBlockBarrier()::__PRETTY_FUNCTION__> "void
cmMakefile::PopLoopBlockBarrier()") at assert.c:92
http://public.kitware.com/Bug/view.php?id=3  0x00007ffff64242f2 in
__GI___assert_fail (assertion=0x769710 "this->LoopBlockCounter.top() == 0",
file=0x769690 "/builddir/build/BUILD/cmake-3.2.2/Source/cmMakefile.cxx",
line=3328, 
    function=0x76abe0 <cmMakefile::PopLoopBlockBarrier()::__PRETTY_FUNCTION__>
"void cmMakefile::PopLoopBlockBarrier()") at assert.c:101
http://public.kitware.com/Bug/view.php?id=4  0x00000000004dce45 in
cmMakefile::PopLoopBlockBarrier (this=0xa39070) at
/usr/src/debug/cmake-3.2.2/Source/cmMakefile.cxx:3328
http://public.kitware.com/Bug/view.php?id=5  0x00000000004e9942 in
cmMakefile::PopScope (this=this at entry=0xa39070) at
/usr/src/debug/cmake-3.2.2/Source/cmMakefile.cxx:4488
http://public.kitware.com/Bug/view.php?id=6  0x00000000005b4c39 in ~ScopePushPop
(this=<synthetic pointer>, __in_chrg=<optimized out>) at
/usr/src/debug/cmake-3.2.2/Source/cmMakefile.h:923
http://public.kitware.com/Bug/view.php?id=7 
cmFunctionHelperCommand::InvokeInitialPass (this=0xa3f7b0, args=...,
inStatus=...) at /usr/src/debug/cmake-3.2.2/Source/cmFunctionCommand.cxx:98
http://public.kitware.com/Bug/view.php?id=8  0x00000000004f3008 in
cmMakefile::ExecuteCommand (this=this at entry=0xa39070, lff=..., status=...) at
/usr/src/debug/cmake-3.2.2/Source/cmMakefile.cxx:385
http://public.kitware.com/Bug/view.php?id=9  0x00000000004f3d3f in
cmMakefile::ReadListFile (this=0xa39070, filename_in=filename_in at entry=0x0,
external_in=external_in at entry=0xa27498 "test.cmake",
fullPath=fullPath at entry=0x0, noPolicyScope=noPolicyScope at entry=true)
    at /usr/src/debug/cmake-3.2.2/Source/cmMakefile.cxx:666
http://public.kitware.com/Bug/view.php?id=10 0x000000000056736e in
cmake::ReadListFile (this=this at entry=0x7fffffffd590, args=..., path=0xa27498
"test.cmake") at /usr/src/debug/cmake-3.2.2/Source/cmake.cxx:508
http://public.kitware.com/Bug/view.php?id=11 0x000000000056e8b7 in
cmake::SetCacheArgs (this=this at entry=0x7fffffffd590, args=...) at
/usr/src/debug/cmake-3.2.2/Source/cmake.cxx:457
http://public.kitware.com/Bug/view.php?id=12 0x00000000005746f6 in cmake::Run
(this=this at entry=0x7fffffffd590, args=..., noconfigure=noconfigure at entry=false)
at /usr/src/debug/cmake-3.2.2/Source/cmake.cxx:1668
http://public.kitware.com/Bug/view.php?id=13 0x000000000049c0a0 in do_cmake
(ac=ac at entry=3, av=av at entry=0xa257d0) at
/usr/src/debug/cmake-3.2.2/Source/cmakemain.cxx:327
http://public.kitware.com/Bug/view.php?id=14 0x0000000000497fdd in main (ac=3,
av=0xa257d0) at /usr/src/debug/cmake-3.2.2/Source/cmakemain.cxx:193


Even though the script itself is malformed, I would expect CMake to handle the
missing endforeach() correctly, like it does outside function(). This is an
output from cmake when running the reproducer as above, just use
macro()/endmacro() instead of function():

CMake Error in test.cmake:
  A logical block opening on the line

    /home/dvratil/test.cmake:2 (foreach)

  is not closed.

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-05-18 08:16 Daniel Vrátil  New Issue                                    
======================================================================



More information about the cmake-developers mailing list