summaryrefslogtreecommitdiffstats
path: root/Source/cmCMakeLanguageCommand.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-05-22 15:50:39 (GMT)
committerBrad King <brad.king@kitware.com>2020-05-26 11:27:35 (GMT)
commit12e483c5633340078a81507a0a81e2cfc34482a5 (patch)
treeefe8e531ff731ee9d7d3a2e0d0ed2ea06cd24068 /Source/cmCMakeLanguageCommand.cxx
parent3ed8b663a9fd6e8d6f7ec0571ab1e3530f9156db (diff)
downloadCMake-12e483c5633340078a81507a0a81e2cfc34482a5.zip
CMake-12e483c5633340078a81507a0a81e2cfc34482a5.tar.gz
CMake-12e483c5633340078a81507a0a81e2cfc34482a5.tar.bz2
cmake_language: check CALL with control command
Fixes: #20739
Diffstat (limited to 'Source/cmCMakeLanguageCommand.cxx')
-rw-r--r--Source/cmCMakeLanguageCommand.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/Source/cmCMakeLanguageCommand.cxx b/Source/cmCMakeLanguageCommand.cxx
index 66857be..eb9269f 100644
--- a/Source/cmCMakeLanguageCommand.cxx
+++ b/Source/cmCMakeLanguageCommand.cxx
@@ -3,15 +3,32 @@
#include "cmCMakeLanguageCommand.h"
#include <algorithm>
+#include <array>
#include <cstddef>
#include <memory>
#include <string>
+#include <cm/string_view>
+#include <cmext/string_view>
+
#include "cmExecutionStatus.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmRange.h"
#include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
+
+namespace {
+std::array<cm::static_string_view, 12> InvalidCommands{
+ { // clang-format off
+ "function"_s, "endfunction"_s,
+ "macro"_s, "endmacro"_s,
+ "if"_s, "elseif"_s, "else"_s, "endif"_s,
+ "while"_s, "endwhile"_s,
+ "foreach"_s, "endforeach"_s
+ } // clang-format on
+};
+}
bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
@@ -64,6 +81,15 @@ bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args,
startArg = 1;
}
+ // ensure specified command is valid
+ // start/end flow control commands are not allowed
+ auto cmd = cmSystemTools::LowerCase(callCommand);
+ if (std::find(InvalidCommands.cbegin(), InvalidCommands.cend(), cmd) !=
+ InvalidCommands.cend()) {
+ status.SetError(cmStrCat("invalid command specified: "_s, callCommand));
+ return false;
+ }
+
cmListFileFunction func;
func.Name = callCommand;
func.Line = context.Line;