From 2c0f6d8c7b04633128470cf5b34dd45abc9cc946 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Mon, 11 Sep 2023 17:55:53 +0100 Subject: [PATCH] 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. --- Userland/Utilities/find.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/find.cpp b/Userland/Utilities/find.cpp index 89b5888e39..ea45bb2945 100644 --- a/Userland/Utilities/find.cpp +++ b/Userland/Utilities/find.cpp @@ -808,12 +808,19 @@ static OwnPtr parse_simple_command(Vector& args) fatal_error("{}: requires additional arguments", arg); g_have_seen_action_command = true; Vector 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(move(command_argv), await_confirmation); } else {