Skip to content

Commit

Permalink
Return family in DNS lookup callback
Browse files Browse the repository at this point in the history
At least in node v0.12.1 on Windows, I was getting assert errors when trying to connect to an address hijacked by `evil-dns`. It turned out to be because the family was not being provided during lookup. When sending the address family to the callback, this was fixed.
  • Loading branch information
jpage-godaddy committed Jun 4, 2015
1 parent 14b6528 commit 9610e2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
7 changes: 4 additions & 3 deletions evil-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ dns.lookup = function(domain, options, callback) {
}

for (i = 0; i < domains.length; i++) {
if (domain.match(domains[i].domain)) {
if (!family || family === domain[i].family) {
return callback(null, domains[i].ip, family);
var entry = domains[i];
if (domain.match(entry.domain)) {
if (!family || family === entry.family) {
return callback(null, entry.ip, entry.family);
}
}
}
Expand Down
35 changes: 24 additions & 11 deletions tests/lookup.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@ var expect = require('chai').expect;
var evilDNS = require('../evil-dns');

describe('The method hijacking dns.lookup', function () {
it('handles family-agnostic queries', function (done) {
var error = null;
try {
dns.lookup('nodejs.org', { family: undefined, hints: dns.ADDRCONFIG | dns.V4MAPPED }, function (err) {
expect(err).to.not.exist;
done();
});
} catch (err) {
expect(err).to.not.exist;
done();
}
it('returns the family when doing DNS queries', function (done) {
evilDNS.add('*.foo.com', '1.2.3.4');
dns.lookup('a.foo.com', {family: undefined, hints: dns.ADDRCONFIG | dns.V4MAPPED}, function (err, addr, family) {
expect(addr).to.equal('1.2.3.4');
expect(family).to.equal(4);
done();
});
});

it('handles family-agnostic queries', function (done) {
var error = null;
try {
dns.lookup('nodejs.org', {family: undefined, hints: dns.ADDRCONFIG | dns.V4MAPPED}, function (err) {
expect(err).to.not.exist;
done();
});
} catch (err) {
expect(err).to.not.exist;
done();
}
});

afterEach(function () {
evilDNS.clear();
});
});

0 comments on commit 9610e2c

Please sign in to comment.