[njs] Fixed backtraces while traversing imported user modules.
Dmitry Volyntsev
xeioex at nginx.com
Mon Feb 14 14:28:27 UTC 2022
details: https://hg.nginx.org/njs/rev/bede4b8a693a
branches:
changeset: 1823:bede4b8a693a
user: Dmitry Volyntsev <xeioex at 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);
More information about the nginx-devel
mailing list