From 16a143c8039fc6dffe70f368bc63b7e0a4618b9a Mon Sep 17 00:00:00 2001 From: islandryu Date: Fri, 24 Oct 2025 19:52:47 +0900 Subject: [PATCH 1/3] inspector: fix crash when receiving non json message --- src/inspector_io.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/inspector_io.cc b/src/inspector_io.cc index ebf3ae4764fa21..361d19349261e5 100644 --- a/src/inspector_io.cc +++ b/src/inspector_io.cc @@ -353,6 +353,9 @@ std::optional InspectorIoDelegate::GetTargetSessionId( std::string_view view(message.data(), message.size()); std::unique_ptr value = protocol::DictionaryValue::cast(JsonUtil::parseJSON(view)); + if (!value) { + return std::nullopt; + } protocol::String target_session_id; protocol::Value* target_session_id_value = value->get("sessionId"); if (target_session_id_value) { From 946ec5a960801e0903ab5ee1057ccbbd26f39a76 Mon Sep 17 00:00:00 2001 From: islandryu Date: Fri, 24 Oct 2025 21:58:45 +0900 Subject: [PATCH 2/3] add test --- .../test-inspector-invalid-protocol.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/parallel/test-inspector-invalid-protocol.js diff --git a/test/parallel/test-inspector-invalid-protocol.js b/test/parallel/test-inspector-invalid-protocol.js new file mode 100644 index 00000000000000..8e0be0ccf9d046 --- /dev/null +++ b/test/parallel/test-inspector-invalid-protocol.js @@ -0,0 +1,39 @@ +'use strict'; +const common = require('../common'); +const { spawn } = require('node:child_process'); +const assert = require('node:assert'); + +(async () => { + const child = spawn( + process.execPath, + ['--inspect-wait=0', '-e', "console.log('test');"], + {} + ); + + const url = await new Promise((resolve) => { + child.stderr.on('data', (data) => { + const msg = data.toString(); + const match = msg.match(/ws:\/\/127\.0\.0\.1:(\d+)\/([a-f0-9-]+)/); + if (match) { + child.stderr.removeAllListeners('data'); + return resolve(match[0]); + } + }); + }); + + child.once('exit', (_, signal) => { + assert.strictEqual(signal, 'SIGTERM'); + }); + + const socket = new WebSocket(url); + + socket.addEventListener('open', common.mustCall(() => { + socket.send('This is not a valid protocol message'); + })); + + socket.addEventListener('message', common.mustCall((event) => { + assert.ok(Object.keys(JSON.parse(event.data)).includes('error')); + socket.close(); + child.kill(); + })); +})().then(common.mustCall()); From db327295171d73e173fa02eb3f15ad4e250f0d65 Mon Sep 17 00:00:00 2001 From: islandryu Date: Mon, 27 Oct 2025 23:24:53 +0900 Subject: [PATCH 3/3] skip if inspector disabled --- test/parallel/test-inspector-invalid-protocol.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-inspector-invalid-protocol.js b/test/parallel/test-inspector-invalid-protocol.js index 8e0be0ccf9d046..28c02028aed472 100644 --- a/test/parallel/test-inspector-invalid-protocol.js +++ b/test/parallel/test-inspector-invalid-protocol.js @@ -1,5 +1,6 @@ 'use strict'; const common = require('../common'); +common.skipIfInspectorDisabled(); const { spawn } = require('node:child_process'); const assert = require('node:assert');