[njs] Fixed parsing of invalid binary expressions.
Alexander Borisov
alexander.borisov at nginx.com
Tue Jun 2 14:54:21 UTC 2020
details: https://hg.nginx.org/njs/rev/ea1754b79e7a
branches:
changeset: 1414:ea1754b79e7a
user: Alexander Borisov <alexander.borisov at nginx.com>
date: Tue Jun 02 17:53:28 2020 +0300
description:
Fixed parsing of invalid binary expressions.
The issue was introduced in 86f55a7dc4a4.
diffstat:
src/njs_parser.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
src/test/njs_unit_test.c | 3 +++
2 files changed, 43 insertions(+), 8 deletions(-)
diffs (176 lines):
diff -r 8923d0751c28 -r ea1754b79e7a src/njs_parser.c
--- a/src/njs_parser.c Tue Jun 02 17:53:27 2020 +0300
+++ b/src/njs_parser.c Tue Jun 02 17:53:28 2020 +0300
@@ -3086,6 +3086,10 @@ njs_parser_expression_node(njs_parser_t
{
njs_parser_node_t *node;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (parser->target != NULL) {
parser->target->right = parser->node;
parser->target->right->dest = parser->target;
@@ -3107,7 +3111,7 @@ njs_parser_expression_node(njs_parser_t
node->left = parser->node;
node->left->dest = node;
- return njs_parser_after(parser, current, node, 1, after);
+ return njs_parser_after(parser, current, node, 0, after);
}
@@ -3398,6 +3402,10 @@ njs_parser_exponentiation_expression_mat
{
njs_parser_node_t *node;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (parser->target != NULL) {
parser->target->right = parser->node;
parser->target->right->dest = parser->target;
@@ -3423,7 +3431,7 @@ njs_parser_exponentiation_expression_mat
njs_parser_next(parser, njs_parser_exponentiation_expression);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, node, 0,
njs_parser_exponentiation_expression_match);
}
@@ -3449,6 +3457,10 @@ njs_parser_multiplicative_expression_mat
njs_parser_node_t *node;
njs_vmcode_operation_t operation;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (parser->target != NULL) {
parser->target->right = parser->node;
parser->target->right->dest = parser->target;
@@ -3485,7 +3497,7 @@ njs_parser_multiplicative_expression_mat
njs_parser_next(parser, njs_parser_exponentiation_expression);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, node, 0,
njs_parser_multiplicative_expression_match);
}
@@ -3511,6 +3523,10 @@ njs_parser_additive_expression_match(njs
njs_parser_node_t *node;
njs_vmcode_operation_t operation;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (parser->target != NULL) {
parser->target->right = parser->node;
parser->target->right->dest = parser->target;
@@ -3543,7 +3559,7 @@ njs_parser_additive_expression_match(njs
njs_parser_next(parser, njs_parser_multiplicative_expression);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, node, 0,
njs_parser_additive_expression_match);
}
@@ -3569,6 +3585,10 @@ njs_parser_shift_expression_match(njs_pa
njs_parser_node_t *node;
njs_vmcode_operation_t operation;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (parser->target != NULL) {
parser->target->right = parser->node;
parser->target->right->dest = parser->target;
@@ -3605,7 +3625,7 @@ njs_parser_shift_expression_match(njs_pa
njs_parser_next(parser, njs_parser_additive_expression);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, node, 0,
njs_parser_shift_expression_match);
}
@@ -3631,6 +3651,10 @@ njs_parser_relational_expression_match(n
njs_parser_node_t *node;
njs_vmcode_operation_t operation;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (parser->target != NULL) {
parser->target->right = parser->node;
parser->target->right->dest = parser->target;
@@ -3679,7 +3703,7 @@ njs_parser_relational_expression_match(n
njs_parser_next(parser, njs_parser_shift_expression);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, node, 0,
njs_parser_relational_expression_match);
}
@@ -3705,6 +3729,10 @@ njs_parser_equality_expression_match(njs
njs_parser_node_t *node;
njs_vmcode_operation_t operation;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
if (parser->target != NULL) {
parser->target->right = parser->node;
parser->target->right->dest = parser->target;
@@ -3745,7 +3773,7 @@ njs_parser_equality_expression_match(njs
njs_parser_next(parser, njs_parser_relational_expression);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, node, 0,
njs_parser_equality_expression_match);
}
@@ -3883,6 +3911,10 @@ njs_parser_coalesce_expression(njs_parse
njs_token_type_t type;
njs_parser_node_t *node;
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
node = parser->node;
if (parser->target != NULL) {
@@ -3916,7 +3948,7 @@ njs_parser_coalesce_expression(njs_parse
njs_parser_next(parser, njs_parser_bitwise_OR_expression);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, node, 0,
njs_parser_coalesce_expression);
}
diff -r 8923d0751c28 -r ea1754b79e7a src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Jun 02 17:53:27 2020 +0300
+++ b/src/test/njs_unit_test.c Tue Jun 02 17:53:28 2020 +0300
@@ -16660,6 +16660,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("new/la"),
njs_str("SyntaxError: Unterminated RegExp \"/la\" in 1") },
+
+ { njs_str("{name; {/ / /}"),
+ njs_str("SyntaxError: Unexpected token \"}\" in 1") },
};
More information about the nginx-devel
mailing list