[njs] Variables may be accessed incorrectly by nested functions.
Igor Sysoev
igor at sysoev.ru
Mon Apr 3 12:11:13 UTC 2017
details: http://hg.nginx.org/njs/rev/c46da90ca064
branches:
changeset: 329:c46da90ca064
user: Igor Sysoev <igor at sysoev.ru>
date: Sun Apr 02 12:36:05 2017 +0300
description:
Variables may be accessed incorrectly by nested functions.
diffstat:
njs/njs_parser.c | 5 +++++
njs/test/njs_unit_test.c | 5 +++++
2 files changed, 10 insertions(+), 0 deletions(-)
diffs (30 lines):
diff -r cee288760080 -r c46da90ca064 njs/njs_parser.c
--- a/njs/njs_parser.c Sun Apr 02 12:35:11 2017 +0300
+++ b/njs/njs_parser.c Sun Apr 02 12:36:05 2017 +0300
@@ -215,6 +215,11 @@ njs_parser_scope_begin(njs_vm_t *vm, njs
if (parent != NULL) {
nxt_queue_insert_tail(&parent->nested, &scope->link);
+
+ if (nesting == 0) {
+ /* Inherit function nesting in blocks. */
+ scope->nesting = parent->nesting;
+ }
}
return NXT_OK;
diff -r cee288760080 -r c46da90ca064 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Sun Apr 02 12:35:11 2017 +0300
+++ b/njs/test/njs_unit_test.c Sun Apr 02 12:36:05 2017 +0300
@@ -4221,6 +4221,11 @@ static njs_unit_test_t njs_test[] =
"var y = f(); y()"),
nxt_string("4") },
+ { nxt_string("function f() { var x = 4;"
+ "function g() { if (1) { return 2 + x; } }; return g }"
+ "var y = f(); y()"),
+ nxt_string("6") },
+
/* Recursive fibonacci. */
{ nxt_string("function fibo(n) {"
More information about the nginx-devel
mailing list