January 16, 2017 09:54AM
details: http://hg.nginx.org/njs/rev/6cc16ad934a4
branches:
changeset: 301:6cc16ad934a4
user: Igor Sysoev <igor@sysoev.ru>
date: Mon Jan 16 17:32:10 2017 +0300
description:
Comprehensive test of "return" statement location.

Found with afl-fuzz.

diffstat:

njs/njs_parser.c | 22 ++++++++++++++--------
njs/test/njs_unit_test.c | 3 +++
2 files changed, 17 insertions(+), 8 deletions(-)

diffs (45 lines):

diff -r 07dc20c1206d -r 6cc16ad934a4 njs/njs_parser.c
--- a/njs/njs_parser.c Mon Jan 16 14:51:29 2017 +0300
+++ b/njs/njs_parser.c Mon Jan 16 17:32:10 2017 +0300
@@ -697,14 +697,20 @@ njs_parser_function_lambda(njs_vm_t *vm,
static njs_token_t
njs_parser_return_statement(njs_vm_t *vm, njs_parser_t *parser)
{
- njs_token_t token;
- njs_parser_node_t *node;
-
- if (parser->scope->type == NJS_SCOPE_GLOBAL) {
- nxt_alert(&vm->trace, NXT_LEVEL_ERROR,
- "SyntaxError: Illegal return statement");
-
- return NXT_ERROR;
+ njs_token_t token;
+ njs_parser_node_t *node;
+ njs_parser_scope_t *scope;
+
+ for (scope = parser->scope;
+ scope->type != NJS_SCOPE_FUNCTION;
+ scope = scope->parent)
+ {
+ if (scope->type == NJS_SCOPE_GLOBAL) {
+ nxt_alert(&vm->trace, NXT_LEVEL_ERROR,
+ "SyntaxError: Illegal return statement");
+
+ return NXT_ERROR;
+ }
}

node = njs_parser_node_alloc(vm);
diff -r 07dc20c1206d -r 6cc16ad934a4 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Mon Jan 16 14:51:29 2017 +0300
+++ b/njs/test/njs_unit_test.c Mon Jan 16 17:32:10 2017 +0300
@@ -3976,6 +3976,9 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("return"),
nxt_string("SyntaxError: Illegal return statement in 1") },

+ { nxt_string("{return}"),
+ nxt_string("SyntaxError: Illegal return statement in 1") },
+
{ nxt_string("function f() { return f() } f()"),
nxt_string("RangeError: Maximum call stack size exceeded") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Comprehensive test of "return" statement location.

Igor Sysoev 1228 January 16, 2017 09:54AM



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

Online Users

Guests: 224
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready