Welcome! Log In Create A New Profile

Advanced

[njs] Fixed String.prototype.replace() when replacer throws exception.

Dmitry Volyntsev
July 07, 2020 08:26AM
details: https://hg.nginx.org/njs/rev/e88aef77c653
branches:
changeset: 1456:e88aef77c653
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Jul 07 12:23:46 2020 +0000
description:
Fixed String.prototype.replace() when replacer throws exception.

This issue was introduced in 1c729f765cfb.
Found by Clang static analyzer.

diffstat:

src/njs_string.c | 4 ++++
src/test/njs_unit_test.c | 3 +++
2 files changed, 7 insertions(+), 0 deletions(-)

diffs (27 lines):

diff -r 7325a6df5036 -r e88aef77c653 src/njs_string.c
--- a/src/njs_string.c Tue Jul 07 12:23:45 2020 +0000
+++ b/src/njs_string.c Tue Jul 07 12:23:46 2020 +0000
@@ -3601,6 +3601,10 @@ njs_string_prototype_replace(njs_vm_t *v
njs_value_arg(&njs_value_undefined),
arguments, 3, &retval);

+ if (njs_slow_path(ret != NJS_OK)) {
+ return ret;
+ }
+
ret = njs_value_to_string(vm, &retval, &retval);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
diff -r 7325a6df5036 -r e88aef77c653 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Jul 07 12:23:45 2020 +0000
+++ b/src/test/njs_unit_test.c Tue Jul 07 12:23:46 2020 +0000
@@ -7523,6 +7523,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("'12345'.replace(3, () => ({toString: () => 'aaaa'}))"),
njs_str("12aaaa45") },

+ { njs_str("'ABC'.replace('B', () => {throw 'OOps'})"),
+ njs_str("OOps") },
+
{ njs_str("'abc'.replace(/a/, 'X')"),
njs_str("Xbc") },

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

[njs] Fixed String.prototype.replace() when replacer throws exception.

Dmitry Volyntsev 66 July 07, 2020 08:26AM



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

Online Users

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