Welcome! Log In Create A New Profile

Advanced

[njs] Global variables may be accessed incorrectly by nested functions.

April 04, 2017 06:26AM
details: http://hg.nginx.org/njs/rev/251aa4b128ea
branches:
changeset: 333:251aa4b128ea
user: Igor Sysoev <igor@sysoev.ru>
date: Tue Apr 04 10:47:02 2017 +0300
description:
Global variables may be accessed incorrectly by nested functions.

diffstat:

njs/njs_variable.c | 6 +++++-
njs/test/njs_unit_test.c | 4 ++++
2 files changed, 9 insertions(+), 1 deletions(-)

diffs (30 lines):

diff -r ada17c8bdd5a -r 251aa4b128ea njs/njs_variable.c
--- a/njs/njs_variable.c Tue Apr 04 10:47:12 2017 +0300
+++ b/njs/njs_variable.c Tue Apr 04 10:47:02 2017 +0300
@@ -322,7 +322,11 @@ njs_variable_get(njs_vm_t *vm, njs_parse
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 -r ada17c8bdd5a -r 251aa4b128ea njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Tue Apr 04 10:47:12 2017 +0300
+++ b/njs/test/njs_unit_test.c Tue Apr 04 10:47:02 2017 +0300
@@ -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) {"
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Global variables may be accessed incorrectly by nested functions.

Igor Sysoev 549 April 04, 2017 06:26AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 81
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready