Skip to content

Commit ee64033

Browse files
authored
dns: fix crash on setServers with port 0
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com> PR-URL: #65009 Fixes: #65006 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
1 parent 85d4755 commit ee64033

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/cares_wrap.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,13 +2275,13 @@ void SetServers(const FunctionCallbackInfo<Value>& args) {
22752275
if (!elm->Get(env->context(), 1).ToLocal(&ipValue)) return;
22762276
if (!elm->Get(env->context(), 2).ToLocal(&portValue)) return;
22772277

2278-
CHECK(familyValue->Int32Value(env->context()).FromJust());
2278+
CHECK(familyValue->IsInt32());
22792279
CHECK(ipValue->IsString());
2280-
CHECK(portValue->Int32Value(env->context()).FromJust());
2280+
CHECK(portValue->IsInt32());
22812281

2282-
int fam = familyValue->Int32Value(env->context()).FromJust();
2282+
int32_t fam = familyValue.As<Int32>()->Value();
22832283
node::Utf8Value ip(env->isolate(), ipValue);
2284-
int port = portValue->Int32Value(env->context()).FromJust();
2284+
int32_t port = portValue.As<Int32>()->Value();
22852285

22862286
if (!csv.empty()) csv += ',';
22872287

test/parallel/test-dns.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ const portsExpected = [
134134
dns.setServers(ports);
135135
assert.deepStrictEqual(dns.getServers(), portsExpected);
136136

137+
// Port 0 means "use the default port" for c-ares.
138+
dns.setServers(['4.4.4.4:0', '[2001:4860:4860::8888]:0']);
139+
assert.deepStrictEqual(dns.getServers(), ['4.4.4.4', '2001:4860:4860::8888']);
140+
137141
// Link-local IPv6 addresses require a zone index (scope id) to be usable;
138142
// c-ares drops link-local servers configured without one.
139143
dns.setServers(['[fe80::483a:5aff:fee6:1f04]%eth0']);

0 commit comments

Comments
 (0)