get_filename_component: Revise PROGRAM/PROGRAM_ARGS split semantics

The KWSys `SystemTools::SplitProgramFromArgs` implementation goes into
an infinite loop when the value is just " " (a space).  Since the
"program path with unquoted spaces plus command-line arguments"
operation it is trying to provide is poorly defined (string parsing
should not depend on filesystem content), just stop using it.

Instead consider the main two use cases the old approach tried to handle:

* The value is the name or absolute path of a program with no quoting
  or escaping, but also no command-line arguments.  In this case we
  can use the value as given with no parsing, and assume no arguments.

* The value is a command-line string containing the program name/path
  plus arguments.  In this case we now assume that the command line
  is properly quoted or escaped.

Fixes: #17262
This commit is contained in:
Brad King
2017-09-11 11:05:20 -04:00
parent 3f8c6cab4b
commit 31f73eb12d
5 changed files with 99 additions and 1 deletions
+24 -1
View File
@@ -60,7 +60,30 @@ bool cmGetFilenameComponentCommand::InitialPass(
}
}
}
cmSystemTools::SplitProgramFromArgs(filename, result, programArgs);
// First assume the path to the program was specified with no
// arguments and with no quoting or escaping for spaces.
// Only bother doing this if there is non-whitespace.
if (!cmSystemTools::TrimWhitespace(filename).empty()) {
result = cmSystemTools::FindProgram(filename);
}
// If that failed then assume a command-line string was given
// and split the program part from the rest of the arguments.
if (result.empty()) {
std::string program;
if (cmSystemTools::SplitProgramFromArgs(filename, program,
programArgs)) {
if (cmSystemTools::FileExists(program)) {
result = program;
} else {
result = cmSystemTools::FindProgram(program);
}
}
if (result.empty()) {
programArgs.clear();
}
}
} else if (args[2] == "EXT") {
result = cmSystemTools::GetFilenameExtension(filename);
} else if (args[2] == "NAME_WE") {