From bc1bbd158e956c888025893d8e585e7f79383f45 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Mon, 14 Feb 2022 14:10:04 +0000 Subject: [PATCH] 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. --- src/njs_builtin.c | 12 +++++++----- test/js/import_native_module_exception.t.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 test/js/import_native_module_exception.t.js diff --git a/src/njs_builtin.c b/src/njs_builtin.c index 14ef6f23..03fac9c9 100644 --- a/src/njs_builtin.c +++ b/src/njs_builtin.c @@ -761,13 +761,15 @@ njs_builtin_match_native_function(njs_vm_t *vm, njs_function_t *function, 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 --git a/test/js/import_native_module_exception.t.js b/test/js/import_native_module_exception.t.js new file mode 100644 index 00000000..64bdff5e --- /dev/null +++ b/test/js/import_native_module_exception.t.js @@ -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); -- 2.47.3