]> git.kaiwu.me - njs.git/commitdiff
Fixed heap-buffer-overflow in lexer.
authorDmitry Volyntsev <xeioex@nginx.com>
Sun, 10 Mar 2019 18:13:26 +0000 (21:13 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Sun, 10 Mar 2019 18:13:26 +0000 (21:13 +0300)
The issue was introduced in 8e2cb4da5e46.

njs/njs_lexer.c
njs/test/njs_unit_test.c

index ca4e6d2c8a2af37947f90ae32d0998ae19ee5cee..82ddc4a1943069ab5e66c9a22bbd9ce148e1dd6f 100644 (file)
@@ -371,7 +371,7 @@ njs_lexer_token_push(njs_vm_t *vm, njs_lexer_t *lexer)
 {
     njs_lexer_token_t  *lt;
 
-    lt = nxt_mp_alloc(vm->mem_pool, sizeof(njs_lexer_token_t));
+    lt = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_lexer_token_t));
     if (nxt_slow_path(lt == NULL)) {
         return NULL;
     }
@@ -542,23 +542,8 @@ njs_lexer_next_token(njs_lexer_t *lexer, njs_lexer_token_t *lt)
 
             /* Fall through. */
 
-        case NJS_TOKEN_BITWISE_NOT:
-        case NJS_TOKEN_OPEN_PARENTHESIS:
-        case NJS_TOKEN_CLOSE_PARENTHESIS:
-        case NJS_TOKEN_OPEN_BRACKET:
-        case NJS_TOKEN_CLOSE_BRACKET:
-        case NJS_TOKEN_OPEN_BRACE:
-        case NJS_TOKEN_CLOSE_BRACE:
-        case NJS_TOKEN_COMMA:
-        case NJS_TOKEN_COLON:
-        case NJS_TOKEN_SEMICOLON:
-        case NJS_TOKEN_CONDITIONAL:
-            lt->text.length = lexer->start - lt->text.start;
-            return token;
-
-        case NJS_TOKEN_ILLEGAL:
         default:
-            lexer->start--;
+            lt->text.length = lexer->start - lt->text.start;
             return token;
         }
 
index 35e874cac54360c9f05b29cfcc884999ccead8b0..8db3fe9363246f3c52b630c5d139fd5e66d80400 100644 (file)
@@ -22,6 +22,9 @@ typedef struct {
 
 static njs_unit_test_t  njs_test[] =
 {
+    { nxt_string("@"),
+      nxt_string("SyntaxError: Unexpected token \"@\" in 1") },
+
     { nxt_string("}"),
       nxt_string("SyntaxError: Unexpected token \"}\" in 1") },