Skip to content

Commit 89b1cf8

Browse files
committed
src: fix crash in GetErrorSource() for invalid using syntax
1 parent d080801 commit 89b1cf8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/node_errors.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ static std::string GetErrorSource(Isolate* isolate,
150150
: 0;
151151
int start = message->GetStartColumn(context).FromMaybe(0);
152152
int end = message->GetEndColumn(context).FromMaybe(0);
153-
if (start >= script_start) {
154-
CHECK_GE(end, start);
153+
if (start >= script_start && end >= script_start) {
155154
start -= script_start;
156155
end -= script_start;
157156
}
@@ -163,6 +162,7 @@ static std::string GetErrorSource(Isolate* isolate,
163162

164163
if (start > end ||
165164
start < 0 ||
165+
end < 0 ||
166166
static_cast<size_t>(end) > sourceline.size()) {
167167
return buf;
168168
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const { spawnSyncAndAssert } = require('../common/child_process');
6+
7+
[
8+
'{using x=null, []=null;}',
9+
'{using x=null, {}=null;}',
10+
'async function f() { { await using x=null, []=null; } }',
11+
'async function f() { { await using x=null, {}=null; } }',
12+
].forEach((script) => {
13+
spawnSyncAndAssert(process.execPath, ['--eval', script], {
14+
status: 1,
15+
signal: null,
16+
stderr(output) {
17+
assert.match(output, /SyntaxError/);
18+
assert.doesNotMatch(output, /Assertion failed/);
19+
assert.doesNotMatch(output, /Native stack trace/);
20+
},
21+
stdout: '',
22+
});
23+
});

0 commit comments

Comments
 (0)