diff options
author | R2RT <artur.ryt@gmail.com> | 2018-04-08 20:56:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-04-09 15:59:07 (GMT) |
commit | aad360eb3d07fc34048f3065e2d3617fa07f2932 (patch) | |
tree | 8149a890d1e37916ab34deaeeedf9beb541c4fa5 | |
parent | 61fd4c742013a7f9139db190f936703b656540ff (diff) | |
download | CMake-aad360eb3d07fc34048f3065e2d3617fa07f2932.zip CMake-aad360eb3d07fc34048f3065e2d3617fa07f2932.tar.gz CMake-aad360eb3d07fc34048f3065e2d3617fa07f2932.tar.bz2 |
Fix crash with --trace-expand --warn-uninitialized together
Some code paths in `ExpandVariablesInString{New,Old}` were not checking
the `filename` parameter for a null pointer, but this can happen when
using the above flags together. Add the checks and a test case.
Fixes: #17896
5 files changed, 20 insertions, 8 deletions
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index bf314bd..ccb4f88 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -101,10 +101,11 @@ const char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) // not been "cleared"/initialized with a set(foo ) call if (this->WarnUninitialized && !this->Makefile->VariableInitialized(var)) { if (this->CheckSystemVars || - cmSystemTools::IsSubDirectory(this->FileName, - this->Makefile->GetHomeDirectory()) || - cmSystemTools::IsSubDirectory( - this->FileName, this->Makefile->GetHomeOutputDirectory())) { + (this->FileName && + (cmSystemTools::IsSubDirectory( + this->FileName, this->Makefile->GetHomeDirectory()) || + cmSystemTools::IsSubDirectory( + this->FileName, this->Makefile->GetHomeOutputDirectory())))) { std::ostringstream msg; msg << "uninitialized variable \'" << var << "\'"; this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index b468208..71359a2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2679,10 +2679,11 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( if (this->GetCMakeInstance()->GetWarnUninitialized() && !this->VariableInitialized(lookup)) { if (this->CheckSystemVars || - cmSystemTools::IsSubDirectory(filename, - this->GetHomeDirectory()) || - cmSystemTools::IsSubDirectory( - filename, this->GetHomeOutputDirectory())) { + (filename && + (cmSystemTools::IsSubDirectory(filename, + this->GetHomeDirectory()) || + cmSystemTools::IsSubDirectory( + filename, this->GetHomeOutputDirectory())))) { std::ostringstream msg; msg << "uninitialized variable \'" << lookup << "\'"; this->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 55eac5e..120a472 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -294,6 +294,10 @@ set(RunCMake_TEST_OPTIONS --trace-expand) run_cmake(trace-expand) unset(RunCMake_TEST_OPTIONS) +set(RunCMake_TEST_OPTIONS --trace-expand --warn-uninitialized) +run_cmake(trace-expand-warn-uninitialized) +unset(RunCMake_TEST_OPTIONS) + set(RunCMake_TEST_OPTIONS --trace-source=trace-only-this-file.cmake) run_cmake(trace-source) unset(RunCMake_TEST_OPTIONS) diff --git a/Tests/RunCMake/CommandLine/trace-expand-warn-uninitialized-stderr.txt b/Tests/RunCMake/CommandLine/trace-expand-warn-uninitialized-stderr.txt new file mode 100644 index 0000000..74429b6 --- /dev/null +++ b/Tests/RunCMake/CommandLine/trace-expand-warn-uninitialized-stderr.txt @@ -0,0 +1,2 @@ +^.*/Tests/RunCMake/CommandLine/CMakeLists.txt\(1\): cmake_minimum_required\(VERSION 3.0 \) +.*/Tests/RunCMake/CommandLine/CMakeLists.txt\(2\): project\(trace-expand-warn-uninitialized NONE \) diff --git a/Tests/RunCMake/CommandLine/trace-expand-warn-uninitialized.cmake b/Tests/RunCMake/CommandLine/trace-expand-warn-uninitialized.cmake new file mode 100644 index 0000000..ec3e4d4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/trace-expand-warn-uninitialized.cmake @@ -0,0 +1,4 @@ +cmake_policy(SET CMP0053 OLD) +message(STATUS "'${uninitialized_variable}'") +cmake_policy(SET CMP0053 NEW) +message(STATUS "'${uninitialized_variable}'") |