Review Request 126931: Fix crash when importing cmake tests whose arguments contain ')'

Andrew Coles andrew.i.coles at
Wed Feb 3 11:00:34 UTC 2016

This is an automatically generated e-mail. To reply, visit:

(Updated Feb. 3, 2016, 11 a.m.)

Review request for KDevelop.


I've extended the test_cmakemanager unit test to try to load a project where there are parentheses in the test arguments.  Without the regexp change it segfaults.

Note: to be able to include the relevant portion of cmakemanager (built from cmakemanager_SRCS) I had to follow the example from elsewhere in the build tree of making a static library for those; then making the actual kdevcmakemanager be built from this and the remaining files in cmakesettings_SRCS.  Apologies if this is considered to be a hack - I have no experience working with plugin .so files to know if there is a proper way of doing this.

Bugs: 358454

Repository: kdevelop


In projectmanagers/cmake/cmakeimportjsonjob.cpp, there's a regular expression that matches 'add_test' lines from CTestTestfile.cmake files, but it stops reading at the first ) character:

`const QRegularExpression rx("add_test *\((.+?) (.*?)\)");`

If the argument list for the add_test line contains brackets, for instance:

add_test(some-test "/some/path" "(foo)" "bar")

...then this causes a segfault a few lines further down - the second rx capture is not a well-formed argument list.

This patch changes the regexp to only stop when ) is at the end of the line:

`const QRegularExpression rx("add_test *\((.+?) (.*?)\) *$");`

It also allows for spaces between the ')' and the end of the line, to be consistent with allowing extra spacing earlier on after add_test.  I'm not sure if this matters in practice but is harmless enough.

Diffs (updated)

  projectmanagers/cmake/CMakeLists.txt 0627fde 
  projectmanagers/cmake/cmakeimportjsonjob.cpp 0502be7 
  projectmanagers/cmake/tests/CMakeLists.txt 451f22d 
  projectmanagers/cmake/tests/manual/parentheses_in_test_arguments/CMakeLists.txt PRE-CREATION 
  projectmanagers/cmake/tests/manual/parentheses_in_test_arguments/main.cpp PRE-CREATION 
  projectmanagers/cmake/tests/manual/parentheses_in_test_arguments/parentheses_in_test_arguments.kdev4 PRE-CREATION 
  projectmanagers/cmake/tests/test_cmakemanager.h 95f3c9c 
  projectmanagers/cmake/tests/test_cmakemanager.cpp 61fd314 



It can now import CTestTestfile.cmake files from my projects without crashing.  I haven't tested it with other people's cmake build trees.

File Attachments

This will cause a seg fault in importTestSuites


Andrew Coles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the KDevelop-devel mailing list