From 89b1cf82e0c5320b23c7c667f092c7b5f8d98465 Mon Sep 17 00:00:00 2001 From: semimikoh Date: Thu, 16 Apr 2026 13:42:23 +0900 Subject: [PATCH 1/2] src: fix crash in GetErrorSource() for invalid using syntax --- src/node_errors.cc | 4 ++-- test/parallel/test-cli-eval-invalid-using.js | 23 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-cli-eval-invalid-using.js diff --git a/src/node_errors.cc b/src/node_errors.cc index 23ca0bc50f68c6..068b1a7c6d83fb 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -150,8 +150,7 @@ static std::string GetErrorSource(Isolate* isolate, : 0; int start = message->GetStartColumn(context).FromMaybe(0); int end = message->GetEndColumn(context).FromMaybe(0); - if (start >= script_start) { - CHECK_GE(end, start); + if (start >= script_start && end >= script_start) { start -= script_start; end -= script_start; } @@ -163,6 +162,7 @@ static std::string GetErrorSource(Isolate* isolate, if (start > end || start < 0 || + end < 0 || static_cast(end) > sourceline.size()) { return buf; } diff --git a/test/parallel/test-cli-eval-invalid-using.js b/test/parallel/test-cli-eval-invalid-using.js new file mode 100644 index 00000000000000..59a8cf8b6e588f --- /dev/null +++ b/test/parallel/test-cli-eval-invalid-using.js @@ -0,0 +1,23 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const { spawnSyncAndAssert } = require('../common/child_process'); + +[ + '{using x=null, []=null;}', + '{using x=null, {}=null;}', + 'async function f() { { await using x=null, []=null; } }', + 'async function f() { { await using x=null, {}=null; } }', +].forEach((script) => { + spawnSyncAndAssert(process.execPath, ['--eval', script], { + status: 1, + signal: null, + stderr(output) { + assert.match(output, /SyntaxError/); + assert.doesNotMatch(output, /Assertion failed/); + assert.doesNotMatch(output, /Native stack trace/); + }, + stdout: '', + }); +}); From 50e788df2b189834f5698d451db1b8b748165424 Mon Sep 17 00:00:00 2001 From: semimikoh Date: Sat, 18 Apr 2026 12:11:34 +0900 Subject: [PATCH 2/2] fixup! src: fix crash in GetErrorSource() for invalid using syntax --- src/node_errors.cc | 4 +--- test/parallel/test-cli-eval-invalid-using.js | 23 -------------------- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 test/parallel/test-cli-eval-invalid-using.js diff --git a/src/node_errors.cc b/src/node_errors.cc index 068b1a7c6d83fb..6bb1b74860ee2c 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -160,9 +160,7 @@ static std::string GetErrorSource(Isolate* isolate, CHECK_GT(buf.size(), 0); *added_exception_line = true; - if (start > end || - start < 0 || - end < 0 || + if (start > end || start < 0 || end < 0 || static_cast(end) > sourceline.size()) { return buf; } diff --git a/test/parallel/test-cli-eval-invalid-using.js b/test/parallel/test-cli-eval-invalid-using.js deleted file mode 100644 index 59a8cf8b6e588f..00000000000000 --- a/test/parallel/test-cli-eval-invalid-using.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -require('../common'); -const assert = require('assert'); -const { spawnSyncAndAssert } = require('../common/child_process'); - -[ - '{using x=null, []=null;}', - '{using x=null, {}=null;}', - 'async function f() { { await using x=null, []=null; } }', - 'async function f() { { await using x=null, {}=null; } }', -].forEach((script) => { - spawnSyncAndAssert(process.execPath, ['--eval', script], { - status: 1, - signal: null, - stderr(output) { - assert.match(output, /SyntaxError/); - assert.doesNotMatch(output, /Assertion failed/); - assert.doesNotMatch(output, /Native stack trace/); - }, - stdout: '', - }); -});