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
This commit is contained in:
R2RT
2018-04-08 22:56:44 +02:00
committed by Brad King
parent 61fd4c7420
commit aad360eb3d
5 changed files with 20 additions and 8 deletions

View File

@@ -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());

View File

@@ -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());

View File

@@ -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)

View File

@@ -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 \)

View File

@@ -0,0 +1,4 @@
cmake_policy(SET CMP0053 OLD)
message(STATUS "'${uninitialized_variable}'")
cmake_policy(SET CMP0053 NEW)
message(STATUS "'${uninitialized_variable}'")