Skip to content

Commit 261fa36

Browse files
evanlucasjasnell
authored andcommitted
src: fix intermittent SIGSEGV in resolveTxt
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 <[email protected]> Reviewed-By: jasnell - James M Snell <[email protected]>
1 parent 1f7257b commit 261fa36

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: src/cares_wrap.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,9 @@ class QueryTxtWrap: public QueryWrap {
633633
}
634634
txt_chunk->Set(j++, txt);
635635
}
636-
// Push last chunk
637-
txt_records->Set(i, txt_chunk);
636+
// Push last chunk if it isn't empty
637+
if (!txt_chunk.IsEmpty())
638+
txt_records->Set(i, txt_chunk);
638639

639640
ares_free_data(txt_out);
640641

Diff for: test/internet/test-dns-txt-sigsegv.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var common = require('../common');
2+
var assert = require('assert');
3+
var dns = require('dns');
4+
5+
dns.resolveTxt('www.microsoft.com', function(err, records) {
6+
assert.equal(err, null);
7+
assert.equal(records.length, 0);
8+
});

0 commit comments

Comments
 (0)