Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 003121c

Browse filesBrowse files
islandryuaduh95
authored andcommitted
inspector: fix crash when receiving non json message
PR-URL: #60388 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
1 parent fd63c27 commit 003121c
Copy full SHA for 003121c

File tree

Expand file treeCollapse file tree

2 files changed

+43
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+43
-0
lines changed
Open diff view settings
Collapse file

‎src/inspector_io.cc‎

Copy file name to clipboardExpand all lines: src/inspector_io.cc
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ std::optional<std::string> InspectorIoDelegate::GetTargetSessionId(
353353
std::string_view view(message.data(), message.size());
354354
std::unique_ptr<protocol::DictionaryValue> value =
355355
protocol::DictionaryValue::cast(JsonUtil::parseJSON(view));
356+
if (!value) {
357+
return std::nullopt;
358+
}
356359
protocol::String target_session_id;
357360
protocol::Value* target_session_id_value = value->get("sessionId");
358361
if (target_session_id_value) {
Collapse file
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
4+
const { spawn } = require('node:child_process');
5+
const assert = require('node:assert');
6+
7+
(async () => {
8+
const child = spawn(
9+
process.execPath,
10+
['--inspect-wait=0', '-e', "console.log('test');"],
11+
{}
12+
);
13+
14+
const url = await new Promise((resolve) => {
15+
child.stderr.on('data', (data) => {
16+
const msg = data.toString();
17+
const match = msg.match(/ws:\/\/127\.0\.0\.1:(\d+)\/([a-f0-9-]+)/);
18+
if (match) {
19+
child.stderr.removeAllListeners('data');
20+
return resolve(match[0]);
21+
}
22+
});
23+
});
24+
25+
child.once('exit', (_, signal) => {
26+
assert.strictEqual(signal, 'SIGTERM');
27+
});
28+
29+
const socket = new WebSocket(url);
30+
31+
socket.addEventListener('open', common.mustCall(() => {
32+
socket.send('This is not a valid protocol message');
33+
}));
34+
35+
socket.addEventListener('message', common.mustCall((event) => {
36+
assert.ok(Object.keys(JSON.parse(event.data)).includes('error'));
37+
socket.close();
38+
child.kill();
39+
}));
40+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.