net: emit error on invalid address family
This commit adds proper error handling to net.connect() when a custom lookup() function returns an invalid address family. PR-URL: https://github.com/nodejs/node/pull/19415 Fixes: https://github.com/nodejs/node/issues/19407 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
0fb017d684
commit
7c73cd4c70
@ -1042,6 +1042,11 @@ The `inspector` module is not available for use.
|
|||||||
While using the `inspector` module, an attempt was made to use the inspector
|
While using the `inspector` module, an attempt was made to use the inspector
|
||||||
before it was connected.
|
before it was connected.
|
||||||
|
|
||||||
|
<a id="ERR_INVALID_ADDRESS_FAMILY"></a>
|
||||||
|
### ERR_INVALID_ADDRESS_FAMILY
|
||||||
|
|
||||||
|
The provided address family is not understood by the Node.js API.
|
||||||
|
|
||||||
<a id="ERR_INVALID_ARG_TYPE"></a>
|
<a id="ERR_INVALID_ARG_TYPE"></a>
|
||||||
### ERR_INVALID_ARG_TYPE
|
### ERR_INVALID_ARG_TYPE
|
||||||
|
|
||||||
|
@ -737,6 +737,7 @@ E('ERR_INSPECTOR_ALREADY_CONNECTED',
|
|||||||
E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error);
|
E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error);
|
||||||
E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available', Error);
|
E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available', Error);
|
||||||
E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected', Error);
|
E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected', Error);
|
||||||
|
E('ERR_INVALID_ADDRESS_FAMILY', 'Invalid address family: %s', RangeError);
|
||||||
E('ERR_INVALID_ARG_TYPE', invalidArgType, TypeError);
|
E('ERR_INVALID_ARG_TYPE', invalidArgType, TypeError);
|
||||||
E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
|
E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
|
||||||
const util = lazyUtil();
|
const util = lazyUtil();
|
||||||
|
@ -54,6 +54,7 @@ const {
|
|||||||
} = require('internal/async_hooks');
|
} = require('internal/async_hooks');
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
const {
|
const {
|
||||||
|
ERR_INVALID_ADDRESS_FAMILY,
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
ERR_INVALID_FD_TYPE,
|
ERR_INVALID_FD_TYPE,
|
||||||
ERR_INVALID_IP_ADDRESS,
|
ERR_INVALID_IP_ADDRESS,
|
||||||
@ -1117,6 +1118,12 @@ function lookupAndConnect(self, options) {
|
|||||||
err.port = options.port;
|
err.port = options.port;
|
||||||
err.message = err.message + ' ' + options.host + ':' + options.port;
|
err.message = err.message + ' ' + options.host + ':' + options.port;
|
||||||
process.nextTick(connectErrorNT, self, err);
|
process.nextTick(connectErrorNT, self, err);
|
||||||
|
} else if (addressType !== 4 && addressType !== 6) {
|
||||||
|
err = new ERR_INVALID_ADDRESS_FAMILY(addressType);
|
||||||
|
err.host = options.host;
|
||||||
|
err.port = options.port;
|
||||||
|
err.message = err.message + ' ' + options.host + ':' + options.port;
|
||||||
|
process.nextTick(connectErrorNT, self, err);
|
||||||
} else {
|
} else {
|
||||||
self._unrefTimer();
|
self._unrefTimer();
|
||||||
defaultTriggerAsyncIdScope(
|
defaultTriggerAsyncIdScope(
|
||||||
|
@ -29,5 +29,14 @@ function connectDoesNotThrow(input) {
|
|||||||
lookup: input
|
lookup: input
|
||||||
};
|
};
|
||||||
|
|
||||||
net.connect(opts);
|
return net.connect(opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Verify that an error is emitted when an invalid address family is returned.
|
||||||
|
const s = connectDoesNotThrow((host, options, cb) => {
|
||||||
|
cb(null, '127.0.0.1', 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
s.on('error', common.expectsError({ code: 'ERR_INVALID_ADDRESS_FAMILY' }));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user