From: Dmitry Volyntsev Date: Mon, 14 Feb 2022 14:10:04 +0000 (+0000) Subject: Fixed backtraces while traversing imported user modules. X-Git-Tag: 0.7.3~12 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=bc1bbd158e956c888025893d8e585e7f79383f45;p=njs.git 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. --- 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);