Skip to content

Commit 90abdd3

Browse files
cjihrigBethGriggs
authored andcommitted
net: validate custom lookup() output
This commit adds validation to the IP address returned by the net module's custom DNS lookup() function. PR-URL: #34813 Fixes: #34812 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 6b45bf3 commit 90abdd3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/net.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,9 @@ function lookupAndConnect(self, options) {
10511051
// calls net.Socket.connect() on it (that's us). There are no event
10521052
// listeners registered yet so defer the error event to the next tick.
10531053
process.nextTick(connectErrorNT, self, err);
1054+
} else if (!isIP(ip)) {
1055+
err = new ERR_INVALID_IP_ADDRESS(ip);
1056+
process.nextTick(connectErrorNT, self, err);
10541057
} else if (addressType !== 4 && addressType !== 6) {
10551058
err = new ERR_INVALID_ADDRESS_FAMILY(addressType,
10561059
options.host,

test/parallel/test-net-dns-custom-lookup.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ function check(addressType, cb) {
4141
check(4, function() {
4242
common.hasIPv6 && check(6);
4343
});
44+
45+
// Verify that bad lookup() IPs are handled.
46+
{
47+
net.connect({
48+
host: 'localhost',
49+
port: 80,
50+
lookup(host, dnsopts, cb) {
51+
cb(null, undefined, 4);
52+
}
53+
}).on('error', common.expectsError({ code: 'ERR_INVALID_IP_ADDRESS' }));
54+
}

0 commit comments

Comments
 (0)