find: Ensure the terminating ; is present when using -exec

The program now terminates with an error if the command passed to
`-exec` is not terminated with a semicolon.

This commit also ensures that the argument containing the terminating
semicolon must be 1 byte long. Previously, any argument whose first
byte was a semicolon was treated as a valid terminator.
This commit is contained in:
Tim Ledbetter 2023-09-11 17:55:53 +01:00 committed by Sam Atkins
parent 8f8354d9a0
commit 2c0f6d8c7b

View file

@ -808,12 +808,19 @@ static OwnPtr<Command> parse_simple_command(Vector<char*>& args)
fatal_error("{}: requires additional arguments", arg);
g_have_seen_action_command = true;
Vector<char*> command_argv;
bool terminator_found = false;
while (!args.is_empty()) {
char* next = args.take_first();
if (next[0] == ';')
if (next[0] == ';' && next[1] == '\0') {
terminator_found = true;
break;
}
command_argv.append(next);
}
if (!terminator_found)
fatal_error("{}: Terminating ';' not found", arg);
auto await_confirmation = (arg == "-ok") ? ExecCommand::AwaitConfirmation::Yes : ExecCommand::AwaitConfirmation::No;
return make<ExecCommand>(move(command_argv), await_confirmation);
} else {