0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

net: validate fds passed to Socket constructor

This commit validates the file descriptor passed to the TTY
wrap's guessHandleType() function. Prior to this commit, a bad
file descriptor would trigger an abort in the binding layer.

PR-URL: https://github.com/nodejs/node/pull/21429
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
cjihrig 2018-06-20 17:27:09 -04:00
parent 7ec6951034
commit d9e95d8982
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
2 changed files with 10 additions and 1 deletions

View File

@ -75,7 +75,7 @@ const {
ERR_SOCKET_BAD_PORT,
ERR_SOCKET_CLOSED
} = errors.codes;
const { validateInt32 } = require('internal/validators');
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
// Lazy loaded to improve startup performance.
@ -93,6 +93,7 @@ const {
function noop() {}
function createHandle(fd, is_server) {
validateInt32(fd, 'fd', 0);
const type = TTYWrap.guessHandleType(fd);
if (type === 'PIPE') {
return new Pipe(

View File

@ -4,6 +4,14 @@ const common = require('../common');
const assert = require('assert');
const net = require('net');
common.expectsError(() => {
new net.Socket({ fd: -1 });
}, { code: 'ERR_OUT_OF_RANGE' });
common.expectsError(() => {
new net.Socket({ fd: 'foo' });
}, { code: 'ERR_INVALID_ARG_TYPE' });
function test(sock, readable, writable) {
let socket;
if (sock instanceof net.Socket) {