Welcome! Log In Create A New Profile

Advanced

[njs] Fixed parsing semicolons.

January 16, 2017 07:02AM
details: http://hg.nginx.org/njs/rev/07dc20c1206d
branches:
changeset: 300:07dc20c1206d
user: Igor Sysoev <igor@sysoev.ru>
date: Mon Jan 16 14:51:29 2017 +0300
description:
Fixed parsing semicolons.

Found with AddressSanitizer.

diffstat:

njs/njs_parser.c | 26 ++++++++++++++++++--------
1 files changed, 18 insertions(+), 8 deletions(-)

diffs (76 lines):

diff -r e4f695e81689 -r 07dc20c1206d njs/njs_parser.c
--- a/njs/njs_parser.c Thu Jan 05 15:55:52 2017 +0300
+++ b/njs/njs_parser.c Mon Jan 16 14:51:29 2017 +0300
@@ -229,11 +229,9 @@ njs_parser_statement_chain(njs_vm_t *vm,

if (nxt_fast_path(token > NJS_TOKEN_ILLEGAL)) {

- if (parser->node != last) {
- /*
- * The statement is not empty block, not just semicolon,
- * and not variables declaration without initialization.
- */
+ if (parser->node != NULL) {
+ /* The statement is not empty block or just semicolon. */
+
node = njs_parser_node_alloc(vm);
if (nxt_slow_path(node == NULL)) {
return NJS_TOKEN_ERROR;
@@ -243,6 +241,15 @@ njs_parser_statement_chain(njs_vm_t *vm,
node->left = last;
node->right = parser->node;
parser->node = node;
+
+ while (token == NJS_TOKEN_SEMICOLON
+ || token == NJS_TOKEN_LINE_END)
+ {
+ token = njs_parser_token(parser);
+ if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ break;
+ }
+ }
}

} else if (vm->exception == NULL) {
@@ -257,6 +264,8 @@ static njs_token_t
njs_parser_statement(njs_vm_t *vm, njs_parser_t *parser,
njs_token_t token)
{
+ parser->node = NULL;
+
switch (token) {

case NJS_TOKEN_FUNCTION:
@@ -296,7 +305,6 @@ njs_parser_statement(njs_vm_t *vm, njs_p
return njs_parser_throw_statement(vm, parser);

case NJS_TOKEN_SEMICOLON:
- parser->node = NULL;
return njs_parser_token(parser);

case NJS_TOKEN_OPEN_BRACE:
@@ -348,13 +356,13 @@ njs_parser_block_statement(njs_vm_t *vm,
return token;
}

- parser->node = NULL;
-
ret = njs_parser_scope_begin(vm, parser, NJS_SCOPE_BLOCK);
if (nxt_slow_path(ret != NXT_OK)) {
return NJS_TOKEN_ERROR;
}

+ parser->node = NULL;
+
while (token != NJS_TOKEN_CLOSE_BRACE) {
token = njs_parser_statement_chain(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
@@ -836,6 +844,8 @@ njs_parser_var_statement(njs_vm_t *vm, n
switch (token) {

case NJS_TOKEN_SEMICOLON:
+ return njs_parser_token(parser);
+
case NJS_TOKEN_CLOSE_BRACE:
case NJS_TOKEN_END:
return token;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed parsing semicolons.

Igor Sysoev 749 January 16, 2017 07:02AM



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

Online Users

Guests: 82
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