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`

Fixes: nodejs/node-v0.x-archive#9285
PR-URL: nodejs/node-v0.x-archive#9300
Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
  • Loading branch information
evanlucas authored and jasnell committed Aug 27, 2015
1 parent 1f7257b commit 261fa36
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 261fa36

Please sign in to comment.