Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspector: fix request path nullptr dereference #9184

Merged
merged 2 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,17 +681,20 @@ bool AgentImpl::RespondToGet(InspectorSocket* socket, const std::string& path) {

if (match_path_segment(command, "list") || command[0] == '\0') {
SendTargentsListResponse(socket);
return true;
} else if (match_path_segment(command, "protocol")) {
SendProtocolJson(socket);
return true;
} else if (match_path_segment(command, "version")) {
SendVersionResponse(socket);
} else {
const char* pid = match_path_segment(command, "activate");
return true;
} else if (const char* pid = match_path_segment(command, "activate")) {
if (pid != id_)
return false;
SendHttpResponse(socket, "Target activated");
return true;
}
return true;
return false;
}

// static
Expand Down
23 changes: 17 additions & 6 deletions test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,17 @@ function checkHttpResponse(port, path, callback) {
res.setEncoding('utf8');
res
.on('data', (data) => response += data.toString())
.on('end', () => callback(JSON.parse(response)));
.on('end', () => {
let err = null;
let json = undefined;
try {
json = JSON.parse(response);
} catch (e) {
err = e;
err.response = response;
}
callback(err, json);
});
});
}

Expand Down Expand Up @@ -284,8 +294,8 @@ TestSession.prototype.disconnect = function(childDone) {

TestSession.prototype.testHttpResponse = function(path, check) {
return this.enqueue((callback) =>
checkHttpResponse(this.harness_.port, path, (response) => {
check.call(this, response);
checkHttpResponse(this.harness_.port, path, (err, response) => {
check.call(this, err, response);
callback();
}));
};
Expand Down Expand Up @@ -352,8 +362,8 @@ Harness.prototype.enqueue_ = function(task) {

Harness.prototype.testHttpResponse = function(path, check) {
return this.enqueue_((doneCallback) => {
checkHttpResponse(this.port, path, (response) => {
check.call(this, response);
checkHttpResponse(this.port, path, (err, response) => {
check.call(this, err, response);
doneCallback();
});
});
Expand Down Expand Up @@ -393,7 +403,8 @@ Harness.prototype.wsHandshake = function(devtoolsUrl, tests, readyCallback) {

Harness.prototype.runFrontendSession = function(tests) {
return this.enqueue_((callback) => {
checkHttpResponse(this.port, '/json/list', (response) => {
checkHttpResponse(this.port, '/json/list', (err, response) => {
assert.ifError(err);
this.wsHandshake(response[0]['webSocketDebuggerUrl'], tests, callback);
});
});
Expand Down
22 changes: 19 additions & 3 deletions test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ const helper = require('./inspector-helper.js');

let scopeId;

function checkListResponse(response) {
function checkListResponse(err, response) {
assert.ifError(err);
assert.strictEqual(1, response.length);
assert.ok(response[0]['devtoolsFrontendUrl']);
assert.ok(
response[0]['webSocketDebuggerUrl']
.match(/ws:\/\/localhost:\d+\/[0-9A-Fa-f]{8}-/));
}

function checkVersion(err, response) {
assert.ifError(err);
assert.ok(response);
}

function checkBadPath(err, response) {
assert(err instanceof SyntaxError);
assert(/Unexpected token/.test(err.message));
assert(/WebSockets request was expected/.test(err.response));
}

function expectMainScriptSource(result) {
const expected = helper.mainScriptSource();
const source = result['scriptSource'];
Expand Down Expand Up @@ -153,7 +165,8 @@ function testInspectScope(session) {
}

function testNoUrlsWhenConnected(session) {
session.testHttpResponse('/json/list', (response) => {
session.testHttpResponse('/json/list', (err, response) => {
assert.ifError(err);
assert.strictEqual(1, response.length);
assert.ok(!response[0].hasOwnProperty('devtoolsFrontendUrl'));
assert.ok(!response[0].hasOwnProperty('webSocketDebuggerUrl'));
Expand All @@ -171,7 +184,10 @@ function runTests(harness) {
harness
.testHttpResponse('/json', checkListResponse)
.testHttpResponse('/json/list', checkListResponse)
.testHttpResponse('/json/version', assert.ok)
.testHttpResponse('/json/version', checkVersion)
.testHttpResponse('/json/activate', checkBadPath)
.testHttpResponse('/json/activate/boom', checkBadPath)
.testHttpResponse('/json/badpath', checkBadPath)
.runFrontendSession([
testNoUrlsWhenConnected,
testBreakpointOnStart,
Expand Down
22 changes: 0 additions & 22 deletions test/parallel/test-v8-inspector-json-protocol.js

This file was deleted.