Skip to content

Commit

Permalink
src: fix intermittent SIGSEGV in resolveTxt
Browse files Browse the repository at this point in the history
Fixes a SIGSEGV by making sure `txt_chunk` is not empty before setting
it on `txt_records`

PR-URL: nodejs/node#960
Reviewed-By: Rod Vagg <rod@vagg.org>
  • Loading branch information
evanlucas authored and Evan Lucas committed Feb 26, 2015
1 parent 5d821fe commit 1a86b98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,9 @@ class QueryTxtWrap: public QueryWrap {
}
txt_chunk->Set(j++, txt);
}
// Push last chunk
txt_records->Set(i, txt_chunk);
// Push last chunk if it isn't empty
if (!txt_chunk.IsEmpty())
txt_records->Set(i, txt_chunk);

ares_free_data(txt_out);

Expand Down
8 changes: 8 additions & 0 deletions test/internet/test-dns-txt-sigsegv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var common = require('../common');
var assert = require('assert');
var dns = require('dns');

dns.resolveTxt('www.microsoft.com', function(err, records) {
assert.equal(err, null);
assert.equal(records.length, 0);
});

0 comments on commit 1a86b98

Please sign in to comment.