MantisBT - CMake
View Issue Details
0013845CMake(No Category)public2013-01-10 15:122013-06-03 09:05
rbmj 
Brad King 
normalcrashalways
closedfixed 
x86_64-linux-gnuDebianWheezy
CMake 2.8.9 
CMake 2.8.11CMake 2.8.11 
0013845: CMake segfault if extra newline in link.txt
The origin of this problem was that I was writing/testing a cross toolchain file which made complicated custom link rules. One of the variables in the link rule came from an execute_process command that had a trailing newline and that, because of its positioning, ended up adding a blank line in the link.txt. This causes cmake to segfault.

This may be rare enough that it's not an issue. Also, I don't have the latest and greatest CMake, so it may already be fixed...

Reproducing is easy though:
Make hello.c:

#include <stdio.h>
int main() {
   printf("Hello, World!\n");
   return 0;
}

and CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
project(hello)
add_executable(hello hello.c)

Go to build directory and run cmake. Then, add a blank line to the beginning of CMakeFiles/hello.dir/link.txt

Run make:

...
Linking C executable hello
Error running link command: Segmentation fault
make[2]: *** [hello] Error 1
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2
No tags attached.
Issue History
2013-01-10 15:12rbmjNew Issue
2013-01-11 09:39Brad KingNote Added: 0032096
2013-01-11 09:39Brad KingAssigned To => Brad King
2013-01-11 09:39Brad KingStatusnew => assigned
2013-01-11 09:39Brad KingTarget Version => CMake 2.8.11
2013-01-11 11:05Brad KingNote Added: 0032097
2013-01-11 11:05Brad KingStatusassigned => resolved
2013-01-11 11:05Brad KingResolutionopen => fixed
2013-01-11 11:05Brad KingFixed in Version => CMake 2.8.11
2013-06-03 09:05Robert MaynardNote Added: 0033186
2013-06-03 09:05Robert MaynardStatusresolved => closed

Notes
(0032096)
Brad King   
2013-01-11 09:39   
Interesting. It is not actually "cmake -E" that is crashing but the child it forks to try to run the command line. We accidentally do exec() with a NULL argv[0] in the child and then the parent reports that it crashed.

I'll work on two fixes for this. First, the process execution API that parses the command line should not add an empty command. Second, we should not try to execute an empty command line anyway.
(0032097)
Brad King   
2013-01-11 11:05   
The second of the fixes I mention in 0013845:0032096 is:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8ff1d471 [^]

and is sufficient to resolve this issue. I'll handle the first (internal API) fix separately.
(0033186)
Robert Maynard   
2013-06-03 09:05   
Closing resolved issues that have not been updated in more than 4 months.