Skip to content

Commit

Permalink
src,inspector: fix empty MaybeLocal crash
Browse files Browse the repository at this point in the history
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 <[email protected]>

PR-URL: #42409
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
RaisinTen authored Apr 9, 2022
1 parent dfc2dc8 commit be01185
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class JSBindingsConnection : public AsyncWrap {
Isolate* isolate = env_->isolate();
HandleScope handle_scope(isolate);
Context::Scope context_scope(env_->context());
MaybeLocal<String> v8string =
String::NewFromTwoByte(isolate, message.characters16(),
NewStringType::kNormal, message.length());
Local<Value> argument = v8string.ToLocalChecked().As<Value>();
Local<Value> argument;
if (!String::NewFromTwoByte(isolate, message.characters16(),
NewStringType::kNormal,
message.length()).ToLocal(&argument)) return;
connection_->OnMessage(argument);
}

Expand Down
20 changes: 20 additions & 0 deletions test/pummel/test-repl-empty-maybelocal-crash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');

if (process.config.variables.arm_version === '7') {
common.skip('Too slow for armv7 bots');
}

// The process should not crash when the REPL receives the string, 'ss'.
// Test for https://github.com/nodejs/node/issues/42407.

const repl = require('repl');

const r = repl.start();

r.write('var buf = Buffer.from({length:200e6},(_,i) => i%256);\n');
r.write('var ss = buf.toString("binary");\n');
r.write('ss');
r.write('.');

r.close();

0 comments on commit be01185

Please sign in to comment.