Closed
Description
backtrace truncated if msg contains null character \0
$ node main.js
abcdef
/main/t02.js:6
throw new Error(a);
^
Error: abc
with this program
function test(){
var a = "abc\0def"
var a2 = "abcdef"
console.log(a); // not truncated
if(true) // change to false and backtrace works
throw new Error(a); // backtrace msg truncated at `\0`, the whole stack frames are missing
else
throw new Error(a2); // backtrace shown correctly
}
test()
without the \0
the backtrace shows fine:
abcdef
/main/t02.js:8
throw new Error(a2);
^
Error: abcdef
at test (/main/t02.js:8:11)
at Object.<anonymous> (/main/t02.js:11:1)
at Module._compile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
at internal/main/run_main_module.js:17:11
node -v
v12.3.1
uname -a
Darwin 18.5.0 Darwin Kernel Version 18.5.0
note
according to https://stackoverflow.com/questions/13698677/null-character-in-strings
a NUL byte should simply be "yet another character value" and have no special meaning, as opposed to other languages where it might end a SV (String value).
console.log correctly shows the string (no truncation) but the backtrace doesn't work when running node on cmd line.
note that on a browser (eg chrome) it works: no truncation:
throw new Error("abc\0def");
VM9405:1 Uncaught Error: abc�def
at <anonymous>:1:7