Skip to content

Commit

Permalink
debugger: guard against call from non-node context
Browse files Browse the repository at this point in the history
Fix a segmentation fault when the debug message handler was called from
a context without an associated `node::Environment`.

Fixes: nodejs#4261
Fixes: nodejs#4322
PR-URL: nodejs#4328
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
bnoordhuis authored and Myles Borins committed Feb 11, 2016
1 parent 12c80a9 commit ed5169b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/debug-agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ void Agent::EnqueueMessage(AgentMessage* message) {
void Agent::MessageHandler(const v8::Debug::Message& message) {
Isolate* isolate = message.GetIsolate();
Environment* env = Environment::GetCurrent(isolate);
if (env == nullptr)
return; // Called from a non-node context.
Agent* a = env->debugger_agent();
CHECK_NE(a, nullptr);
CHECK_EQ(isolate, a->parent_env()->isolate());
Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-debug-no-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;

const args = [`--debug`, `--debug-port=${common.PORT}`, `--interactive`];
const proc = spawn(process.execPath, args, { stdio: 'pipe' });
proc.stdin.write(`
util.inspect(Promise.resolve(42));
util.inspect(Promise.resolve(1337));
.exit
`);
proc.on('exit', common.mustCall((exitCode, signalCode) => {
assert.strictEqual(exitCode, 0);
assert.strictEqual(signalCode, null);
}));
let stdout = '';
proc.stdout.setEncoding('utf8');
proc.stdout.on('data', data => stdout += data);
process.on('exit', () => {
assert(stdout.includes('Promise { 42 }'));
assert(stdout.includes('Promise { 1337 }'));
});

0 comments on commit ed5169b

Please sign in to comment.