Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

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#9285
PR-URL: nodejs#9300
Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
  • Loading branch information
evanlucas authored and jBarz committed Nov 4, 2016
1 parent 43ea23a commit 655fbb9
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 655fbb9

Please sign in to comment.