ctest: Prevent infinite loop in ctest_run_script(NEW_PROCESS)

ctest passes an internal -SR argument to inform a subprocess which
script to run. Because all arguments are propagated to the subprocess,
nested subprocess receives multiple -SR arguments and re-runs
the parent script in addition to its own, leading to a loop.

Ignore redundant -SR arguments on input and also filter out parent's
-SR argument when constructing a child process.

Fixes: #8837
This commit is contained in:
Nikita Nemkin 2025-02-04 14:43:06 +05:00
parent c10cb0fde9
commit cb5f136c66
2 changed files with 12 additions and 4 deletions

View File

@ -97,7 +97,12 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg)
this->CTest->GetInitialCommandLineArguments();
//*** need to make sure this does not have the current script ***
for (size_t i = 1; i < initArgs.size(); ++i) {
argv.push_back(initArgs[i]);
// in a nested subprocess, skip the parent's `-SR <path>` arguments.
if (initArgs[i] == "-SR") {
i++; // <path>
} else {
argv.push_back(initArgs[i]);
}
}
// Now create process object

View File

@ -1975,9 +1975,12 @@ int cmCTest::Run(std::vector<std::string> const& args)
};
auto const dashSR =
[&runScripts, &SRArgumentSpecified](std::string const& script) -> bool {
SRArgumentSpecified = true;
runScripts.emplace_back(cmSystemTools::ToNormalizedPathOnDisk(script),
true);
// -SR should be processed only once
if (!SRArgumentSpecified) {
SRArgumentSpecified = true;
runScripts.emplace_back(cmSystemTools::ToNormalizedPathOnDisk(script),
true);
}
return true;
};
auto const dash_S =