From 4e89e1828e2cc51b1b5e651092a0db0567ad9955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Tokodi?= Date: Tue, 18 Jun 2024 20:00:07 +0200 Subject: [PATCH] Fix parsing of invalid private class properties (#5144) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Raise syntax error instead of failing with an assert JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi mate.tokodi@szteszoftver.hu --- jerry-core/parser/js/js-parser-expr.c | 5 ++++- tests/jerry/fail/regression-test-issue-5141.js | 15 +++++++++++++++ tools/cppcheck/suppressions-list | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/jerry/fail/regression-test-issue-5141.js diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index d079d762b..1324e907d 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -405,7 +405,10 @@ static void parser_check_duplicated_private_field (parser_context_t *context_p, /**< context */ uint8_t opts) /**< options */ { - JERRY_ASSERT (context_p->token.type == LEXER_LITERAL); + if (context_p->token.type != LEXER_LITERAL) + { + parser_raise_error (context_p, PARSER_ERR_EXPRESSION_EXPECTED); + } JERRY_ASSERT (context_p->private_context_p); scanner_class_private_member_t *iter = context_p->private_context_p->members_p; diff --git a/tests/jerry/fail/regression-test-issue-5141.js b/tests/jerry/fail/regression-test-issue-5141.js new file mode 100644 index 000000000..94b57ca41 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-5141.js @@ -0,0 +1,15 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +class C { #get [Symbol]; } diff --git a/tools/cppcheck/suppressions-list b/tools/cppcheck/suppressions-list index 0431fb380..d65b4aa62 100644 --- a/tools/cppcheck/suppressions-list +++ b/tools/cppcheck/suppressions-list @@ -31,7 +31,7 @@ shiftNegativeLHS:jerry-math/*.c shiftTooManyBits:jerry-core/*.c shiftTooManyBitsSigned:jerry-math/*.c signConversionCond:jerry-core/*.c -uninitvar:jerry-core/parser/js/js-parser-expr.c:3420 +uninitvar:jerry-core/parser/js/js-parser-expr.c:3423 uninitvar:tests/unit-core/test-api-objecttype.c:119 unmatchedSuppression:jerry-core/*.inc.h unreadVariable:jerry-core/*.c