Permalink
Browse files

dns, bugfix: dns.resolve crash on Linux.

  • Loading branch information...
xicilion committed Jun 5, 2018
1 parent 85b3d19 commit 415231013957ac1ad9b41c7711650d064979099d
Showing with 14 additions and 3 deletions.
  1. +3 −3 fibjs/src/net/net.cpp
  2. +11 −0 test/dns_test.js
View
@@ -33,7 +33,7 @@ result_t dns_base::resolve(exlib::string name, obj_ptr<NArray>& retVal, AsyncEve
int res = getaddrinfo(name.c_str(), NULL, &hints, &result);
if (res)
return CHECK_ERROR(-res);
return CHECK_ERROR(Runtime::setError(gai_strerror(res)));
obj_ptr<NArray> arr = new NArray();
for (ptr = result; ptr != NULL; ptr = ptr->ai_next) {
@@ -60,7 +60,7 @@ result_t dns_base::lookup(exlib::string name, exlib::string& retVal, AsyncEvent*
int res = getaddrinfo(name.c_str(), NULL, &hints, &result);
if (res)
return CHECK_ERROR(-res);
return CHECK_ERROR(Runtime::setError(gai_strerror(res)));
for (ptr = result; ptr != NULL; ptr = ptr->ai_next) {
inetAddr addr_info;
@@ -100,7 +100,7 @@ result_t net_base::resolve(exlib::string name, int32_t family,
int res = getaddrinfo(name.c_str(), NULL, &hints, &result);
if (res)
return CHECK_ERROR(-res);
return CHECK_ERROR(Runtime::setError(gai_strerror(res)));
for (ptr = result; ptr != NULL; ptr = ptr->ai_next)
if (ptr->ai_family == addr_info.addr4.sin_family) {
View
@@ -1,4 +1,5 @@
const dns = require('dns');
const net = require('net');
const test = require('test');
test.setup();
@@ -22,6 +23,16 @@ describe('dns', () => {
dns.lookup('999.999.999.999');
});
});
it('net.resolve', () => {
net.resolve('fibjs.org');
});
it('FIX: crash in net.resolve when host is unknown', () => {
assert.throws(() => {
net.resolve('999.999.999.999');
});
});
});
require.main === module && test.run(console.DEBUG);

0 comments on commit 4152310

Please sign in to comment.