Permalink
Browse files

dns, bugfix: result error in dns.resolve and dns.lookup when host is …

…unknown.
  • Loading branch information...
xicilion committed Jun 5, 2018
1 parent 5c2dd77 commit f1bb38002c0e2f9b42a4a5e26c8cf76fb8544292
Showing with 34 additions and 4 deletions.
  1. +6 −4 fibjs/src/net/net.cpp
  2. +27 −0 test/dns_test.js
  3. +1 −0 test/main.js
View
@@ -31,8 +31,9 @@ result_t dns_base::resolve(exlib::string name, obj_ptr<NArray>& retVal, AsyncEve
addrinfo* result = NULL;
addrinfo* ptr = NULL;
if (getaddrinfo(name.c_str(), NULL, &hints, &result))
return CHECK_ERROR(SocketError());
int res = getaddrinfo(name.c_str(), NULL, &hints, &result);
if (res)
return CHECK_ERROR(-res);
obj_ptr<NArray> arr = new NArray();
for (ptr = result; ptr != NULL; ptr = ptr->ai_next) {
@@ -57,8 +58,9 @@ result_t dns_base::lookup(exlib::string name, exlib::string& retVal, AsyncEvent*
addrinfo* result = NULL;
addrinfo* ptr = NULL;
if (getaddrinfo(name.c_str(), NULL, &hints, &result))
return CHECK_ERROR(SocketError());
int res = getaddrinfo(name.c_str(), NULL, &hints, &result);
if (res)
return CHECK_ERROR(-res);
for (ptr = result; ptr != NULL; ptr = ptr->ai_next) {
inetAddr addr_info;
View
@@ -0,0 +1,27 @@
const dns = require('dns');
const test = require('test');
test.setup();
describe('dns', () => {
it('dns.resolve', () => {
dns.resolve('fibjs.org');
});
it('FIX: crash in dns.resolve when host is unknown', () => {
assert.throws(() => {
dns.resolve('999.999.999.999');
});
});
it('dns.lookup', () => {
dns.lookup('fibjs.org');
});
it('FIX: error result in dns.lookup when host is unknown', () => {
assert.throws(() => {
dns.lookup('999.999.999.999');
});
});
});
require.main === module && test.run(console.DEBUG);
View
@@ -32,6 +32,7 @@ run("./process_test.js");
run("./encoding_test.js");
run("./json_test.js");
run("./module_test.js");
run("./dns_test.js");
run("./net_test.js");
run("./dgram_test.js");
run("./buffered_test.js");

0 comments on commit f1bb380

Please sign in to comment.