summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorEvan Wilde <etceterawilde@gmail.com>2023-08-07 18:14:14 (GMT)
committerBrad King <brad.king@kitware.com>2023-08-07 23:17:29 (GMT)
commit88f90a72f11bfdd16da63681ba3a5c482cf07304 (patch)
tree3cbeb2918de1201eff7bcb4688da609dadd4b917 /Source
parentcbcd2978268a31fde7e9893dd0da13659dadd166 (diff)
downloadCMake-88f90a72f11bfdd16da63681ba3a5c482cf07304.zip
CMake-88f90a72f11bfdd16da63681ba3a5c482cf07304.tar.gz
CMake-88f90a72f11bfdd16da63681ba3a5c482cf07304.tar.bz2
file(GENERATE): Restore INPUT|CONTENT parse checking
Refactoring in commit bff468c988 (cmFileCommand: Use cm::optional for keyword argument presence, 2022-06-30, v3.25.0-rc1~512^2) accidentally broke the check that the input argument is either `INPUT` or `CONTENT`. The check is supposed to fail when arguments are passed in the wrong order. For example: file(GENERATE OUTPUT ... TARGET <target> CONTENT <content>) Prior to this fix, the input method would be CONTENT, but because the first parsed keyword is not `CONTENT`, `inputIsContent` would be false. The first parsed keyword isn't INPUT either, so we would not continue into the error condition. CMake would then try to handle this as an input file, when there isn't one, resulting in uninitialized memory usage and segfaults or corruption later on. Fixes: #25169
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFileCommand.cxx3
1 files changed, 2 insertions, 1 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 45fba8b..8f2ebf5 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -2555,8 +2555,9 @@ bool HandleGenerateCommand(std::vector<std::string> const& args,
return false;
}
const bool inputIsContent = arguments.ParsedKeywords[1] == "CONTENT"_s;
- if (!inputIsContent && arguments.ParsedKeywords[1] == "INPUT") {
+ if (!inputIsContent && arguments.ParsedKeywords[1] != "INPUT") {
status.SetError("Unknown argument to GENERATE subcommand.");
+ return false;
}
std::string const& input =
inputIsContent ? *arguments.Content : *arguments.Input;