From: Igor Sysoev Date: Tue, 4 Apr 2017 07:47:02 +0000 (+0300) Subject: Global variables may be accessed incorrectly by nested functions. X-Git-Tag: 0.1.10~5 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=6867829c9e28ad89b8720831732b0b297a8076e3;p=njs.git Global variables may be accessed incorrectly by nested functions. --- diff --git a/njs/njs_variable.c b/njs/njs_variable.c index f6e05591..03a28e01 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -322,7 +322,11 @@ njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node) goto not_found; } - n = (node->scope->nesting != vs.scope->nesting); + n = 0; + + if (vs.scope->type > NJS_SCOPE_GLOBAL) { + n = (node->scope->nesting != vs.scope->nesting); + } var = vs.variable; index = var->index; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 81f729c5..4a5aaa7c 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -4319,6 +4319,10 @@ static njs_unit_test_t njs_test[] = "var y = f(); y()"), nxt_string("6") }, + { nxt_string("var x; var y = 4;" + "function f() { function h() { x = 3; return y; } }"), + nxt_string("undefined") }, + /* Recursive fibonacci. */ { nxt_string("function fibo(n) {"