From fef165f1d202a5ad712af2074c6f302f8cc07b4d Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 22 Mar 2021 16:12:00 +0430 Subject: [PATCH] Spreadsheet: Do not assume that user input has balanced parenthesis Otherwise people with broken paren keys, or people with entertaining ideas like "=9\b)" will cause an assert to trip. Fixes #5909. --- Userland/Applications/Spreadsheet/JSIntegration.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/Spreadsheet/JSIntegration.cpp b/Userland/Applications/Spreadsheet/JSIntegration.cpp index 695298f479a..b62c89298e2 100644 --- a/Userland/Applications/Spreadsheet/JSIntegration.cpp +++ b/Userland/Applications/Spreadsheet/JSIntegration.cpp @@ -64,6 +64,10 @@ Optional get_function_and_argument_index(StringView so case JS::TokenType::ParenClose: previous_was_identifier = false; if (open_parens_since_last_commit == 0) { + if (state.is_empty() || names.is_empty()) { + // JS Syntax error. + break; + } state.take_last(); names.take_last(); break; @@ -73,7 +77,8 @@ Optional get_function_and_argument_index(StringView so case JS::TokenType::Comma: previous_was_identifier = false; if (open_parens_since_last_commit == 0 && open_curlies_and_brackets_since_last_commit == 0) { - state.last()++; + if (!state.is_empty()) + state.last()++; break; } break;