Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a757f00

Browse filesBrowse files
geeksilva97aduh95
authored andcommitted
net: emit an error when custom lookup resolves to a non-string address
PR-URL: #57192 Fixes: #57112 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 0ac977d commit a757f00
Copy full SHA for a757f00

File tree

Expand file treeCollapse file tree

2 files changed

+45
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+45
-1
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ function lookupAndConnect(self, options) {
14161416
// calls net.Socket.connect() on it (that's us). There are no event
14171417
// listeners registered yet so defer the error event to the next tick.
14181418
process.nextTick(connectErrorNT, self, err);
1419-
} else if (!isIP(ip)) {
1419+
} else if ((typeof ip !== 'string') || !isIP(ip)) {
14201420
err = new ERR_INVALID_IP_ADDRESS(ip);
14211421
process.nextTick(connectErrorNT, self, err);
14221422
} else if (addressType !== 4 && addressType !== 6) {
Collapse file
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as common from '../common/index.mjs';
2+
import net from 'node:net';
3+
import { describe, it } from 'node:test';
4+
5+
const brokenCustomLookup = (_hostname, options, callback) => {
6+
// Incorrectly return an array of IPs instead of a string.
7+
callback(null, ['127.0.0.1'], options.family);
8+
};
9+
10+
describe('when family is ipv4', () => {
11+
it('socket emits an error when lookup does not return a string', (t, done) => {
12+
const options = {
13+
host: 'example.com',
14+
port: 80,
15+
lookup: brokenCustomLookup,
16+
family: 4
17+
};
18+
19+
const socket = net.connect(options, common.mustNotCall());
20+
socket.on('error', (err) => {
21+
t.assert.strictEqual(err.code, 'ERR_INVALID_IP_ADDRESS');
22+
23+
done();
24+
});
25+
});
26+
});
27+
28+
describe('when family is ipv6', () => {
29+
it('socket emits an error when lookup does not return a string', (t, done) => {
30+
const options = {
31+
host: 'example.com',
32+
port: 80,
33+
lookup: brokenCustomLookup,
34+
family: 6
35+
};
36+
37+
const socket = net.connect(options, common.mustNotCall());
38+
socket.on('error', (err) => {
39+
t.assert.strictEqual(err.code, 'ERR_INVALID_IP_ADDRESS');
40+
41+
done();
42+
});
43+
});
44+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.