[njs] Limiting recursion depth while compiling unary expressions.

Dmitry Volyntsev xeioex at nginx.com
Tue Aug 27 14:15:27 UTC 2019


details:   https://hg.nginx.org/njs/rev/4fd921f02096
branches:  
changeset: 1144:4fd921f02096
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Aug 27 16:31:00 2019 +0300
description:
Limiting recursion depth while compiling unary expressions.

This extends 8057f3ad56c1 and is related to #146 issue on Github.

diffstat:

 src/njs_parser_expression.c |  40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diffs (106 lines):

diff -r 12e9519e7eb4 -r 4fd921f02096 src/njs_parser_expression.c
--- a/src/njs_parser_expression.c	Mon Aug 26 19:00:13 2019 +0300
+++ b/src/njs_parser_expression.c	Tue Aug 27 16:31:00 2019 +0300
@@ -225,7 +225,12 @@ njs_parser_assignment_expression(njs_vm_
     njs_parser_node_t       *node;
     njs_vmcode_operation_t  operation;
 
+    njs_parser_enter(vm, parser);
+
     token = njs_parser_conditional_expression(vm, parser, token);
+
+    njs_parser_leave(parser);
+
     if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
         return token;
     }
@@ -332,7 +337,12 @@ njs_parser_assignment_expression(njs_vm_
             return token;
         }
 
+        njs_parser_enter(vm, parser);
+
         token = njs_parser_assignment_expression(vm, parser, token);
+
+        njs_parser_leave(parser);
+
         if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
             return token;
         }
@@ -494,7 +504,12 @@ njs_parser_exponential_expression(njs_vm
             return token;
         }
 
+        njs_parser_enter(vm, parser);
+
         token = njs_parser_exponential_expression(vm, parser, NULL, token);
+
+        njs_parser_leave(parser);
+
         if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
             return token;
         }
@@ -558,7 +573,12 @@ njs_parser_unary_expression(njs_vm_t *vm
         return next;
     }
 
+    njs_parser_enter(vm, parser);
+
     next = njs_parser_unary_expression(vm, parser, NULL, next);
+
+    njs_parser_leave(parser);
+
     if (njs_slow_path(next <= NJS_TOKEN_ILLEGAL)) {
         return next;
     }
@@ -740,16 +760,16 @@ static njs_token_t
 njs_parser_call_expression(njs_vm_t *vm, njs_parser_t *parser,
     njs_token_t token)
 {
+    njs_parser_enter(vm, parser);
+
     if (token == NJS_TOKEN_NEW) {
         token = njs_parser_new_expression(vm, parser, token);
 
     } else {
-        njs_parser_enter(vm, parser);
+        token = njs_parser_terminal(vm, parser, token);
+    }
 
-        token = njs_parser_terminal(vm, parser, token);
-
-        njs_parser_leave(parser);
-    }
+    njs_parser_leave(parser);
 
     if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
         return token;
@@ -868,23 +888,23 @@ njs_parser_new_expression(njs_vm_t *vm, 
         return token;
     }
 
+    njs_parser_enter(vm, parser);
+
     if (token == NJS_TOKEN_NEW) {
         token = njs_parser_new_expression(vm, parser, token);
 
     } else {
-        njs_parser_enter(vm, parser);
-
         token = njs_parser_terminal(vm, parser, token);
-
-        njs_parser_leave(parser);
-
         if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+            njs_parser_leave(parser);
             return token;
         }
 
         token = njs_parser_property_expression(vm, parser, token);
     }
 
+    njs_parser_leave(parser);
+
     if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
         return token;
     }


More information about the nginx-devel mailing list