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 90abdd3

Browse filesBrowse 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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6b45bf3 commit 90abdd3
Copy full SHA for 90abdd3

File tree

Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+3Lines 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,
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-net-dns-custom-lookup.js
+11Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.