Welcome! Log In Create A New Profile

Advanced

[njs] Fixed backtraces while traversing imported user modules.

Dmitry Volyntsev
February 14, 2022 09:32AM
details: https://hg.nginx.org/njs/rev/bede4b8a693a
branches:
changeset: 1823:bede4b8a693a
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Feb 14 14:10:04 2022 +0000
description:
Fixed backtraces while traversing imported user modules.

Previously, njs_builtin_match_native_function(), which is used to build a
backtrace for an exception, assumed that user modules always return
object values, which is not the case. As a result, njs_object_traverse()
may receive incorrect pointer.

This fix is to only traverse object values.

diffstat:

src/njs_builtin.c | 12 +++++++-----
test/js/import_native_module_exception.t.js | 12 ++++++++++++
2 files changed, 19 insertions(+), 5 deletions(-)

diffs (40 lines):

diff -r 4d38ea471228 -r bede4b8a693a src/njs_builtin.c
--- a/src/njs_builtin.c Thu Jan 27 13:01:55 2022 +0000
+++ b/src/njs_builtin.c Mon Feb 14 14:10:04 2022 +0000
@@ -761,13 +761,15 @@ njs_builtin_match_native_function(njs_vm
break;
}

- ctx.match = module->name;
+ if (njs_is_object(&module->value)) {
+ ctx.match = module->name;

- ret = njs_object_traverse(vm, njs_object(&module->value), &ctx,
- njs_builtin_traverse);
+ ret = njs_object_traverse(vm, njs_object(&module->value), &ctx,
+ njs_builtin_traverse);

- if (ret == NJS_DONE) {
- goto found;
+ if (ret == NJS_DONE) {
+ goto found;
+ }
}
}

diff -r 4d38ea471228 -r bede4b8a693a test/js/import_native_module_exception.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/import_native_module_exception.t.js Mon Feb 14 14:10:04 2022 +0000
@@ -0,0 +1,12 @@
+/*---
+includes: []
+flags: []
+paths: [test/js/module, test/js/module/libs]
+negative:
+ phase: runtime
+---*/
+
+import fs from 'fs';
+import lib from 'lib3.js';
+
+fs.readFileSync({}.a.a);
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Fixed backtraces while traversing imported user modules.

Dmitry Volyntsev 520 February 14, 2022 09:32AM



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

Online Users

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