Skip to content

Commit be01185

Browse files
authored
src,inspector: fix empty MaybeLocal crash
Return early when the Inspector StringView to V8 String conversion fails and returns an empty MaybeLocal instead of running the invalid ToLocalChecked() assertion. Fixes: #42407 Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: #42409 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent dfc2dc8 commit be01185

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/inspector_js_api.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ class JSBindingsConnection : public AsyncWrap {
7575
Isolate* isolate = env_->isolate();
7676
HandleScope handle_scope(isolate);
7777
Context::Scope context_scope(env_->context());
78-
MaybeLocal<String> v8string =
79-
String::NewFromTwoByte(isolate, message.characters16(),
80-
NewStringType::kNormal, message.length());
81-
Local<Value> argument = v8string.ToLocalChecked().As<Value>();
78+
Local<Value> argument;
79+
if (!String::NewFromTwoByte(isolate, message.characters16(),
80+
NewStringType::kNormal,
81+
message.length()).ToLocal(&argument)) return;
8282
connection_->OnMessage(argument);
8383
}
8484

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (process.config.variables.arm_version === '7') {
5+
common.skip('Too slow for armv7 bots');
6+
}
7+
8+
// The process should not crash when the REPL receives the string, 'ss'.
9+
// Test for https://github.com/nodejs/node/issues/42407.
10+
11+
const repl = require('repl');
12+
13+
const r = repl.start();
14+
15+
r.write('var buf = Buffer.from({length:200e6},(_,i) => i%256);\n');
16+
r.write('var ss = buf.toString("binary");\n');
17+
r.write('ss');
18+
r.write('.');
19+
20+
r.close();

0 commit comments

Comments
 (0)