From 2f0da06e9024b0254ec3256ecd631ae17902636a Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Mon, 26 Oct 2026 15:22:42 -0400 Subject: [PATCH] cmGeneratorExpressionParser: Fix crash on "$<" at end of input When a previous expression in the input has already been closed, parsing continued to the next `$<`, and when that's at the end, it stepped past. --- Source/cmGeneratorExpressionParser.cxx | 5 +++++ Tests/GeneratorExpression/CMakeLists.txt | 2 ++ Tests/GeneratorExpression/check-part2.cmake | 2 ++ 3 files changed, 9 insertions(+) diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx index 2443893517..b9e7c07901 100644 --- a/Source/cmGeneratorExpressionParser.cxx +++ b/Source/cmGeneratorExpressionParser.cxx @@ -224,6 +224,11 @@ void cmGeneratorExpressionParser::ParseContent( case cmGeneratorExpressionToken::BeginExpression: assert(this->it != this->Tokens.end()); ++this->it; + if (this->it == this->Tokens.end()) { + // A '$<' at the end of the input is plain text. + extendText(result, this->it - 1); + return; + } this->ParseGeneratorExpression(result); return; case cmGeneratorExpressionToken::EndExpression: diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index 18b545ba36..be9a4c3706 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -144,6 +144,8 @@ add_custom_target(check-part2 ALL -Dtest_incomplete_19=$<1:some,thing$ -Dtest_incomplete_20=$ -Dtest_incomplete_21=$ + -Dtest_incomplete_22=$<1:a>$< + -Dtest_incomplete_23=$<1:a>$<1:$< -Dtest_build_interface=$ -Dtest_install_interface=$ -Dtest_target_name_1=$ diff --git a/Tests/GeneratorExpression/check-part2.cmake b/Tests/GeneratorExpression/check-part2.cmake index edf4d3c8ad..2b92de974f 100644 --- a/Tests/GeneratorExpression/check-part2.cmake +++ b/Tests/GeneratorExpression/check-part2.cmake @@ -22,6 +22,8 @@ check(test_incomplete_18 "$<1:some,thing") check(test_incomplete_19 "$<1:some,thing>") check(test_incomplete_20 "$") check(test_incomplete_21 "$") +check(test_incomplete_22 "a$<") +check(test_incomplete_23 "a$<1:$<") check(test_build_interface "build") check(test_install_interface "") check(test_target_name_1 "tgt,ok")