util: fix isInsideNodeModules inside error
When isInsideNodeModules gets called while already processing another stack trace, V8 will not call prepareStackTrace again. This used to cause Node.js to just crash — fix it by checking for expected return type of the stack (Array). PR-URL: https://github.com/nodejs/node/pull/20266 Fixes: https://github.com/nodejs/node/issues/20258 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
99d56a4749
commit
16aee380a5
@ -356,16 +356,17 @@ function isInsideNodeModules() {
|
||||
|
||||
// Iterate over all stack frames and look for the first one not coming
|
||||
// from inside Node.js itself:
|
||||
for (const frame of stack) {
|
||||
const filename = frame.getFileName();
|
||||
// If a filename does not start with / or contain \,
|
||||
// it's likely from Node.js core.
|
||||
if (!/^\/|\\/.test(filename))
|
||||
continue;
|
||||
return kNodeModulesRE.test(filename);
|
||||
if (Array.isArray(stack)) {
|
||||
for (const frame of stack) {
|
||||
const filename = frame.getFileName();
|
||||
// If a filename does not start with / or contain \,
|
||||
// it's likely from Node.js core.
|
||||
if (!/^\/|\\/.test(filename))
|
||||
continue;
|
||||
return kNodeModulesRE.test(filename);
|
||||
}
|
||||
}
|
||||
|
||||
return false; // This should be unreachable.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
17
test/parallel/test-buffer-constructor-deprecation-error.js
Normal file
17
test/parallel/test-buffer-constructor-deprecation-error.js
Normal file
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
const bufferWarning = 'Buffer() is deprecated due to security and usability ' +
|
||||
'issues. Please use the Buffer.alloc(), ' +
|
||||
'Buffer.allocUnsafe(), or Buffer.from() methods instead.';
|
||||
|
||||
common.expectWarning('DeprecationWarning', bufferWarning, 'DEP0005');
|
||||
|
||||
// This is used to make sure that a warning is only emitted once even though
|
||||
// `new Buffer()` is called twice.
|
||||
process.on('warning', common.mustCall());
|
||||
|
||||
Error.prepareStackTrace = (err, trace) => new Buffer(10);
|
||||
|
||||
new Error().stack;
|
Loading…
x
Reference in New Issue
Block a user