FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

dns: fix crash on setServers with port 0 · nodejs/node@e9327d1 · GitHub

/ node Public

Commit e9327d1

Browse files
authored andcommitted
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 615273d commit e9327d1

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
@@ -2159,13 +2159,13 @@ void SetServers(const FunctionCallbackInfo<Value>& args) {
21592159
if (!elm->Get(env->context(), 1).ToLocal(&ipValue)) return;
21602160
if (!elm->Get(env->context(), 2).ToLocal(&portValue)) return;
21612161

2162-
CHECK(familyValue->Int32Value(env->context()).FromJust());
2162+
CHECK(familyValue->IsInt32());
21632163
CHECK(ipValue->IsString());
2164-
CHECK(portValue->Int32Value(env->context()).FromJust());
2164+
CHECK(portValue->IsInt32());
21652165

2166-
int fam = familyValue->Int32Value(env->context()).FromJust();
2166+
int32_t fam = familyValue.As<Int32>()->Value();
21672167
node::Utf8Value ip(env->isolate(), ipValue);
2168-
int port = portValue->Int32Value(env->context()).FromJust();
2168+
int32_t port = portValue.As<Int32>()->Value();
21692169

21702170
ares_addr_port_node* cur = &servers[i];
21712171

‎test/parallel/test-dns.js‎

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

139+
// Port 0 means "use the default port" for c-ares.
140+
dns.setServers(['4.4.4.4:0', '[2001:4860:4860::8888]:0']);
141+
assert.deepStrictEqual(dns.getServers(), ['4.4.4.4', '2001:4860:4860::8888']);
142+
139143
dns.setServers([]);
140144
assert.deepStrictEqual(dns.getServers(), []);
141145

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL