Welcome! Log In Create A New Profile

Advanced

[njs] Fixed RegExp.prototype.[@@split]() with UTF8 strings.

Dmitry Volyntsev
June 11, 2021 02:30PM
details: https://hg.nginx.org/njs/rev/a0f5719c8d9a
branches:
changeset: 1658:a0f5719c8d9a
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Jun 11 15:47:37 2021 +0000
description:
Fixed RegExp.prototype.[@@split]() with UTF8 strings.

Found by OSS-Fuzz.

diffstat:

src/njs_regexp.c | 3 ++-
src/test/njs_unit_test.c | 3 +++
2 files changed, 5 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r 1c066436ec55 -r a0f5719c8d9a src/njs_regexp.c
--- a/src/njs_regexp.c Fri Jun 11 15:15:48 2021 +0000
+++ b/src/njs_regexp.c Fri Jun 11 15:47:37 2021 +0000
@@ -1828,7 +1828,8 @@ njs_regexp_prototype_symbol_split(njs_vm
end = &s.start[s.size];

if (utf8 == NJS_STRING_UTF8) {
- start = njs_string_offset(s.start, s.start + s.size, p);
+ start = (p < length) ? njs_string_offset(s.start, s.start + s.size, p)
+ : end;

} else {
start = &s.start[p];
diff -r 1c066436ec55 -r a0f5719c8d9a src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Jun 11 15:15:48 2021 +0000
+++ b/src/test/njs_unit_test.c Fri Jun 11 15:47:37 2021 +0000
@@ -8861,6 +8861,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("'abc'.split(/abc/)"),
njs_str(",") },

+ { njs_str("('α'.repeat(32)).split(/./).length"),
+ njs_str("33") },
+
{ njs_str("'AbcDefGhi'.split(/([A-Z][a-z]+)/)"),
njs_str(",Abc,,Def,,Ghi,") },

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

[njs] Fixed RegExp.prototype.[@@split]() with UTF8 strings.

Dmitry Volyntsev 121 June 11, 2021 02:30PM



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

Online Users

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