[njs] Added necessary checks for obligatory grammar symbols.
Alexander Borisov
alexander.borisov at nginx.com
Tue Jun 2 14:54:23 UTC 2020
details: https://hg.nginx.org/njs/rev/4117ec04714b
branches:
changeset: 1415:4117ec04714b
user: Alexander Borisov <alexander.borisov at nginx.com>
date: Tue Jun 02 17:53:29 2020 +0300
description:
Added necessary checks for obligatory grammar symbols.
The issue was introduced in 86f55a7dc4a4.
diffstat:
src/njs_parser.c | 14 +++++++++++++-
src/test/njs_unit_test.c | 12 ++++++++++++
2 files changed, 25 insertions(+), 1 deletions(-)
diffs (67 lines):
diff -r ea1754b79e7a -r 4117ec04714b src/njs_parser.c
--- a/src/njs_parser.c Tue Jun 02 17:53:28 2020 +0300
+++ b/src/njs_parser.c Tue Jun 02 17:53:29 2020 +0300
@@ -888,6 +888,10 @@ static njs_int_t
njs_parser_close_parenthesis(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (token->type != NJS_TOKEN_CLOSE_PARENTHESIS) {
return njs_parser_failed(parser);
}
@@ -1590,6 +1594,10 @@ njs_parser_array_after(njs_parser_t *par
{
njs_int_t ret;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
ret = njs_parser_array_item(parser, parser->target, parser->node);
if (ret != NJS_OK) {
return NJS_ERROR;
@@ -1617,7 +1625,7 @@ static njs_int_t
njs_parser_array_spread_element(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- if (token->type != NJS_TOKEN_CLOSE_BRACKET) {
+ if (parser->ret != NJS_OK || token->type != NJS_TOKEN_CLOSE_BRACKET) {
return njs_parser_failed(parser);
}
@@ -6262,6 +6270,10 @@ njs_parser_catch_finally(njs_parser_t *p
{
njs_parser_node_t *node;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
node = njs_parser_node_new(parser, NJS_TOKEN_FINALLY);
if (node == NULL) {
return NJS_ERROR;
diff -r ea1754b79e7a -r 4117ec04714b src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Jun 02 17:53:28 2020 +0300
+++ b/src/test/njs_unit_test.c Tue Jun 02 17:53:29 2020 +0300
@@ -16663,6 +16663,18 @@ static njs_unit_test_t njs_test[] =
{ njs_str("{name; {/ / /}"),
njs_str("SyntaxError: Unexpected token \"}\" in 1") },
+
+ { njs_str("[(]"),
+ njs_str("SyntaxError: Unexpected token \"]\" in 1") },
+
+ { njs_str("[...]"),
+ njs_str("SyntaxError: Unexpected token \"]\" in 1") },
+
+ { njs_str("switch () {}"),
+ njs_str("SyntaxError: Unexpected token \")\" in 1") },
+
+ { njs_str("switch ([(]) {}"),
+ njs_str("SyntaxError: Unexpected token \"]\" in 1") },
};
More information about the nginx-devel
mailing list