[njs] Fixed parsing of invalid unary expression.

Alexander Borisov alexander.borisov at nginx.com
Wed Jun 3 17:50:33 UTC 2020


details:   https://hg.nginx.org/njs/rev/61dce54ce3d5
branches:  
changeset: 1420:61dce54ce3d5
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Wed Jun 03 20:49:52 2020 +0300
description:
Fixed parsing of invalid unary expression.

The issue was introduced in 86f55a7dc4a4.

diffstat:

 src/njs_parser.c         |   6 +++++-
 src/test/njs_unit_test.c |  24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletions(-)

diffs (57 lines):

diff -r 4737eb75961e -r 61dce54ce3d5 src/njs_parser.c
--- a/src/njs_parser.c	Wed Jun 03 15:17:51 2020 +0300
+++ b/src/njs_parser.c	Wed Jun 03 20:49:52 2020 +0300
@@ -3304,7 +3304,7 @@ njs_parser_unary_expression(njs_parser_t
 
     parser->target = node;
 
-    return njs_parser_after(parser, current, node, 1,
+    return njs_parser_after(parser, current, node, 0,
                             njs_parser_unary_expression_next);
 }
 
@@ -3332,6 +3332,10 @@ njs_parser_unary_expression_next(njs_par
     njs_token_type_t   type;
     njs_parser_node_t  *node;
 
+    if (parser->ret != NJS_OK) {
+        return njs_parser_failed(parser);
+    }
+
     type = parser->target->token_type;
     node = parser->node;
 
diff -r 4737eb75961e -r 61dce54ce3d5 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Jun 03 15:17:51 2020 +0300
+++ b/src/test/njs_unit_test.c	Wed Jun 03 20:49:52 2020 +0300
@@ -16696,6 +16696,30 @@ static njs_unit_test_t  njs_test[] =
 
     { njs_str("switch ([(]) {}"),
       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("{{}{delete}"),
+      njs_str("SyntaxError: Unexpected token \"}\" in 1") },
+
+    { njs_str("{{}{++}"),
+      njs_str("SyntaxError: Unexpected token \"}\" in 1") },
+
+    { njs_str("{{}{++1}"),
+      njs_str("ReferenceError: Invalid left-hand side in prefix operation in 1") },
+
+    { njs_str("{{}{1++}"),
+      njs_str("ReferenceError: Invalid left-hand side in postfix operation in 1") },
+
+    { njs_str("{{}{1/}"),
+      njs_str("SyntaxError: Unexpected token \"}\" in 1") },
+
+    { njs_str("{{}{1>>}"),
+      njs_str("SyntaxError: Unexpected token \"}\" in 1") },
 };
 
 


More information about the nginx-devel mailing list