summaryrefslogtreecommitdiff
path: root/Source/cmListCommand.cxx
diff options
context:
space:
mode:
authorNick Muggio <nick@mugg.io>2021-12-08 20:54:04 -0500
committerNick Muggio <nick@mugg.io>2021-12-08 20:54:04 -0500
commit7dd3e99270431cace5086c62f4ee73441b9edc5e (patch)
tree2d1dda5d74af6f6e2a25377ae69c92cea86d5bd9 /Source/cmListCommand.cxx
parenta54f18ff36f0dc47d565c111785515bc5e287c24 (diff)
downloadcmake-7dd3e99270431cace5086c62f4ee73441b9edc5e.tar.gz
cmListCommand: Handle invalid FOR selector ranges
Fixes crashes involving invalid ranges specified in list(TRANSFORM ... FOR ...) calls. * Report error when step is not positive * Report error when start is after stop Fixes: #22985
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r--Source/cmListCommand.cxx13
1 files changed, 11 insertions, 2 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index b35832797d..56345df010 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -678,6 +678,14 @@ public:
this->Start = this->NormalizeIndex(this->Start, count);
this->Stop = this->NormalizeIndex(this->Stop, count);
+ // Does stepping move us further from the end?
+ if (this->Start > this->Stop) {
+ throw transform_error(
+ cmStrCat("sub-command TRANSFORM, selector FOR "
+ "expects <start> to be no greater than <stop> (",
+ this->Start, " > ", this->Stop, ")"));
+ }
+
// compute indexes
auto size = (this->Stop - this->Start + 1) / this->Step;
if ((this->Stop - this->Start + 1) % this->Step != 0) {
@@ -1026,9 +1034,10 @@ bool HandleTransformCommand(std::vector<std::string> const& args,
}
}
- if (step < 0) {
+ if (step <= 0) {
status.SetError("sub-command TRANSFORM, selector FOR expects "
- "non negative numeric value for <step>.");
+ "positive numeric value for <step>.");
+ return false;
}
command.Selector =