Welcome! Log In Create A New Profile

Advanced

[njs] Fixed parsing of hex, oct and binary literals with no digits.

Vadim Zhestikov via nginx-devel
January 29, 2024 12:02PM
details: https://hg.nginx.org/njs/rev/a2959e490279
branches:
changeset: 2275:a2959e490279
user: Vadim Zhestikov <v.zhestikov@f5.com>
date: Mon Jan 29 08:57:49 2024 -0800
description:
Fixed parsing of hex, oct and binary literals with no digits.

diffstat:

src/njs_lexer.c | 6 +++---
src/test/njs_unit_test.c | 15 ++++++++++++---
2 files changed, 15 insertions(+), 6 deletions(-)

diffs (69 lines):

diff -r 08d7391230be -r a2959e490279 src/njs_lexer.c
--- a/src/njs_lexer.c Mon Jan 29 08:57:48 2024 -0800
+++ b/src/njs_lexer.c Mon Jan 29 08:57:49 2024 -0800
@@ -915,7 +915,7 @@ njs_lexer_number(njs_lexer_t *lexer, njs
if (*p == 'x' || *p == 'X') {
p++;

- if (p == lexer->end) {
+ if (p == lexer->end || njs_char_to_hex(*p) < 0) {
goto illegal_token;
}

@@ -929,7 +929,7 @@ njs_lexer_number(njs_lexer_t *lexer, njs
if (*p == 'o' || *p == 'O') {
p++;

- if (p == lexer->end) {
+ if (p == lexer->end || (u_char)(*p - '0') > 7) {
goto illegal_token;
}

@@ -947,7 +947,7 @@ njs_lexer_number(njs_lexer_t *lexer, njs
if (*p == 'b' || *p == 'B') {
p++;

- if (p == lexer->end) {
+ if (p == lexer->end || (u_char)(*p - '0') > 1) {
goto illegal_token;
}

diff -r 08d7391230be -r a2959e490279 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Mon Jan 29 08:57:48 2024 -0800
+++ b/src/test/njs_unit_test.c Mon Jan 29 08:57:49 2024 -0800
@@ -353,7 +353,10 @@ static njs_unit_test_t njs_test[] =
njs_str("SyntaxError: Unexpected token \"0O778\" in 1") },

{ njs_str("0O_7"),
- njs_str("SyntaxError: Unexpected token \"_7\" in 1") },
+ njs_str("SyntaxError: Unexpected token \"0O\" in 1") },
+
+ { njs_str("0O + 1"),
+ njs_str("SyntaxError: Unexpected token \"0O\" in 1") },

{ njs_str("0o7_"),
njs_str("SyntaxError: Unexpected token \"_\" in 1") },
@@ -408,7 +411,10 @@ static njs_unit_test_t njs_test[] =
njs_str("SyntaxError: Unexpected token \"0B12\" in 1") },

{ njs_str("0b_11"),
- njs_str("SyntaxError: Unexpected token \"_11\" in 1") },
+ njs_str("SyntaxError: Unexpected token \"0b\" in 1") },
+
+ { njs_str("0b + 1"),
+ njs_str("SyntaxError: Unexpected token \"0b\" in 1") },

{ njs_str("0B1__1"),
njs_str("SyntaxError: Unexpected token \"__1\" in 1") },
@@ -446,7 +452,10 @@ static njs_unit_test_t njs_test[] =
njs_str("SyntaxError: Unexpected token \"g\" in 1") },

{ njs_str("0X_ff"),
- njs_str("SyntaxError: Unexpected token \"_ff\" in 1") },
+ njs_str("SyntaxError: Unexpected token \"0X\" in 1") },
+
+ { njs_str("0X + 1"),
+ njs_str("SyntaxError: Unexpected token \"0X\" in 1") },

{ njs_str("0xff_"),
njs_str("SyntaxError: Unexpected token \"_\" in 1") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed parsing of hex, oct and binary literals with no digits.

Vadim Zhestikov via nginx-devel 190 January 29, 2024 12:02PM



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

Online Users

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