Commit 6f2701ab authored by Brad King's avatar Brad King
Browse files

CPack: Fix crash on invalid generator name

In commit v3.11.0-rc1~68^2 (CPack: accept --trace and --trace-expand,
2017-12-09) a nullptr dereference was added that occurs when
`cpack -G NotAGenerator` is invoked.  Add the needed condition.

Fixes: #17900
parent 61fd4c74
...@@ -350,16 +350,16 @@ int main(int argc, char const* const* argv) ...@@ -350,16 +350,16 @@ int main(int argc, char const* const* argv)
} }
if (parsed) { if (parsed) {
cpackGenerator = generators.NewGenerator(gen); cpackGenerator = generators.NewGenerator(gen);
if (!cpackGenerator) { if (cpackGenerator) {
cpackGenerator->SetTrace(trace);
cpackGenerator->SetTraceExpand(traceExpand);
} else {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot initialize CPack generator: " << gen "Cannot initialize CPack generator: " << gen
<< std::endl); << std::endl);
parsed = 0; parsed = 0;
} }
cpackGenerator->SetTrace(trace);
cpackGenerator->SetTraceExpand(traceExpand);
if (parsed && !cpackGenerator->Initialize(gen, mf)) { if (parsed && !cpackGenerator->Initialize(gen, mf)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot initialize the generator " << gen "Cannot initialize the generator " << gen
......
...@@ -335,6 +335,7 @@ add_RunCMake_test(CommandLine -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}) ...@@ -335,6 +335,7 @@ add_RunCMake_test(CommandLine -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
add_RunCMake_test(CommandLineTar) add_RunCMake_test(CommandLineTar)
add_RunCMake_test(install) add_RunCMake_test(install)
add_RunCMake_test(CPackCommandLine)
add_RunCMake_test(CPackConfig) add_RunCMake_test(CPackConfig)
add_RunCMake_test(CPackInstallProperties) add_RunCMake_test(CPackInstallProperties)
add_RunCMake_test(ExternalProject) add_RunCMake_test(ExternalProject)
......
^CPack Error: Cannot initialize CPack generator: NotAGenerator
include(RunCMake)
set(RunCMake_TEST_TIMEOUT 60)
file(WRITE "${RunCMake_BINARY_DIR}/NotAGenerator-build/CPackConfig.cmake" [[
set(CPACK_PACKAGE_NAME "Test")
set(CPACK_PACKAGE_VERSION "1")
]])
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(NotAGenerator ${CMAKE_CPACK_COMMAND} -G NotAGenerator)
unset(RunCMake_TEST_NO_CLEAN)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment