Bug 358454 - Crash when importing cmake tests if test arguments contain )
Summary: Crash when importing cmake tests if test arguments contain )
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Build tools: CMake (show other bugs)
Version: 4.90.91
Platform: Other Linux
: NOR crash
Target Milestone: 5.0.0
Assignee: kdevelop-bugs-null
URL:
Keywords: release_blocker
Depends on:
Blocks:
 
Reported: 2016-01-23 22:00 UTC by Andrew Coles
Modified: 2016-02-14 16:55 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Coles 2016-01-23 22:00:19 UTC
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.

I've worked around this in my copy of the sources by changing the regexp to:

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

That is, only stop if the ) character is at the end of the line.  That way, ) characters in the argument list are fine.

Reproducible: Always

Steps to Reproduce:
Create a CMake test:

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

..then try to import the project.

Actual Results:  
It segfaults

Expected Results:  
It should load the test

I'm using the 5.0 branch from the git repo.
Comment 1 Kevin Funk 2016-02-02 20:07:02 UTC
Patch at: https://git.reviewboard.kde.org/r/126931/
Comment 2 Milian Wolff 2016-02-14 16:55:15 UTC
Git commit 45a9d54799192a693e071326a8766450f5765e82 by Milian Wolff, on behalf of Andrew Coles.
Committed on 14/02/2016 at 16:53.
Pushed by mwolff into branch '5.0'.

Fix crash when importing cmake tests whose arguments contain ')'

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.

REVIEW: 126931

>From f45971369c78cc88b03a9b11067fa28f65b84ce2 Mon Sep 17 00:00:00 2001
From: Andrew Coles <andrew.i.coles@googlemail.com>
Date: Wed, 3 Feb 2016 10:52:18 +0000
Subject: [PATCH] Bug fix, and unit test - no longer crash if test arguments
 contain parentheses

M  +6    -0    projectmanagers/cmake/CMakeLists.txt
M  +1    -1    projectmanagers/cmake/cmakeimportjsonjob.cpp
M  +1    -1    projectmanagers/cmake/tests/CMakeLists.txt
A  +5    -0    projectmanagers/cmake/tests/manual/parentheses_in_test_arguments/CMakeLists.txt
A  +2    -0    projectmanagers/cmake/tests/manual/parentheses_in_test_arguments/main.cpp     [License: UNKNOWN]  *
A  +3    -0    projectmanagers/cmake/tests/manual/parentheses_in_test_arguments/parentheses_in_test_arguments.kdev4
M  +13   -0    projectmanagers/cmake/tests/test_cmakemanager.cpp
M  +1    -0    projectmanagers/cmake/tests/test_cmakemanager.h

The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


http://commits.kde.org/kdevelop/45a9d54799192a693e071326a8766450f5765e82