dns: coerce -0 to +0 in lookup and resolver inputs

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63556
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Filip Skokan authored and Antoine du Hamel committed 2026-07-30 13:51:29 +02:00
1 parent 7cdad636c4
commit d4cfe2d8ac
4 files changed
+30 -7

No files matched your search

+6 -3
View File
@@ -158,7 +158,8 @@ function lookup(hostname, options, callback) {
validateFunction(callback, 'callback');
validateOneOf(options, 'family', validFamilies);
family = options;
// Coerce -0 to +0.
family = options + 0;
} else if (options !== undefined && typeof options !== 'object') {
validateFunction(arguments.length === 2 ? options : callback, 'callback');
throw new ERR_INVALID_ARG_TYPE('options', ['integer', 'object'], options);
@@ -180,7 +181,8 @@ function lookup(hostname, options, callback) {
break;
default:
validateOneOf(options.family, 'options.family', validFamilies);
family = options.family;
// Coerce -0 to +0.
family = options.family + 0;
break;
}
}
@@ -280,7 +282,8 @@ function lookupService(address, port, callback) {
validateFunction(callback, 'callback');
port = +port;
// Coerce -0 to +0.
port = +port + 0;
const req = new GetNameInfoReqWrap();
req.callback = callback;
+4 -2
View File
@@ -207,7 +207,8 @@ function lookup(hostname, options) {
if (typeof options === 'number') {
validateOneOf(options, 'family', validFamilies);
family = options;
// Coerce -0 to +0.
family = options + 0;
} else if (options !== undefined && typeof options !== 'object') {
throw new ERR_INVALID_ARG_TYPE('options', ['integer', 'object'], options);
} else {
@@ -218,7 +219,8 @@ function lookup(hostname, options) {
}
if (options?.family != null) {
validateOneOf(options.family, 'options.family', validFamilies);
family = options.family;
// Coerce -0 to +0.
family = options.family + 0;
}
if (options?.all != null) {
validateBoolean(options.all, 'options.all');
+6 -2
View File
@@ -45,14 +45,18 @@ const {
} = require('internal/v8/startup_snapshot');
function validateTimeout(options) {
const { timeout = -1 } = { ...options };
let { timeout = -1 } = { ...options };
validateInt32(timeout, 'options.timeout', -1);
// Coerce -0 to +0.
timeout += 0;
return timeout;
}
function validateMaxTimeout(options) {
const { maxTimeout = 0 } = { ...options };
let { maxTimeout = 0 } = { ...options };
validateUint32(maxTimeout, 'options.maxTimeout');
// Coerce -0 to +0.
maxTimeout += 0;
return maxTimeout;
}
+14
View File
@@ -0,0 +1,14 @@
'use strict';
const common = require('../common');
const dns = require('dns');
dns.lookup('localhost', -0, common.mustCall());
dns.lookup('localhost', { family: -0 }, common.mustCall());
dns.lookupService('127.0.0.1', -0, common.mustCall());
new dns.Resolver({ timeout: -0 });
new dns.Resolver({ maxTimeout: -0 });
dns.promises.lookup('localhost', { family: -0 }).then(common.mustCall());