Skip to content

Commit 7d1d739

Browse files
bnoordhuisMylesBorins
authored andcommitted
src: fix inspector nullptr deref on abrupt exit
Fix a nullptr dereference on abrupt termination when async call stack recording is enabled. Bug discovered while trying to write a regression test for the bug fix in commit df79b7d ("src: fix missing handlescope bug in inspector".) PR-URL: #17577 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]>
1 parent 1a84005 commit 7d1d739

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/inspector_agent.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,12 @@ class NodeInspectorClient : public V8InspectorClient {
325325
}
326326

327327
void maxAsyncCallStackDepthChanged(int depth) override {
328-
if (depth == 0) {
329-
env_->inspector_agent()->DisableAsyncHook();
330-
} else {
331-
env_->inspector_agent()->EnableAsyncHook();
328+
if (auto agent = env_->inspector_agent()) {
329+
if (depth == 0) {
330+
agent->DisableAsyncHook();
331+
} else {
332+
agent->EnableAsyncHook();
333+
}
332334
}
333335
}
334336

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Check that abrupt termination when async call stack recording is enabled
2+
// does not segfault the process.
3+
'use strict';
4+
const common = require('../common');
5+
common.skipIfInspectorDisabled();
6+
common.skipIf32Bits();
7+
8+
const { strictEqual } = require('assert');
9+
const eyecatcher = 'nou, houdoe he?';
10+
11+
if (process.argv[2] === 'child') {
12+
const { Session } = require('inspector');
13+
const { promisify } = require('util');
14+
const { registerAsyncHook } = process.binding('inspector');
15+
(async () => {
16+
let enabled = 0;
17+
registerAsyncHook(() => ++enabled, () => {});
18+
const session = new Session();
19+
session.connect();
20+
session.post = promisify(session.post);
21+
await session.post('Debugger.enable');
22+
strictEqual(enabled, 0);
23+
await session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 42 });
24+
strictEqual(enabled, 1);
25+
throw new Error(eyecatcher);
26+
})();
27+
} else {
28+
const { spawnSync } = require('child_process');
29+
const options = { encoding: 'utf8' };
30+
const proc = spawnSync(process.execPath, [__filename, 'child'], options);
31+
strictEqual(proc.status, 0);
32+
strictEqual(proc.signal, null);
33+
strictEqual(proc.stderr.includes(eyecatcher), true);
34+
}

0 commit comments

Comments
 (0)