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

http_parser: assert on incoming argument's type #12288

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ class Parser : public AsyncWrap {
static void Consume(const FunctionCallbackInfo<Value>& args) {
Parser* parser;
ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
CHECK(args[0]->IsExternal());
Local<External> stream_obj = args[0].As<External>();
StreamBase* stream = static_cast<StreamBase*>(stream_obj->Value());
CHECK_NE(stream, nullptr);
Expand Down
28 changes: 28 additions & 0 deletions test/abort/test-http-parser-consume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const spawn = require('child_process').spawn;

if (process.argv[2] === 'child') {
const server = http.createServer(common.mustCall((req, res) => {
res.end('hello');
}));

server.listen(0, common.mustCall((s) => {
const rr = http.get(
{ port: server.address().port },
common.mustCall((d) => {
// This bad input (0) should abort the parser and the process
rr.parser.consume(0);
server.close();
}));
}));
} else {
const child = spawn(process.execPath, [__filename, 'child'],
{ stdio: 'inherit' });
child.on('exit', common.mustCall((code, signal) => {
assert(common.nodeProcessAborted(code, signal),
'process should have aborted, but did not');
}));
}