src: fix intermittent SIGSEGV in resolveTxt
authorEvan Lucas <evanlucas@me.com>
Wed, 25 Feb 2015 22:59:29 +0000 (16:59 -0600)
committerEvan Lucas <evan@btc.com>
Thu, 26 Feb 2015 04:45:35 +0000 (22:45 -0600)
Fixes a SIGSEGV by making sure `txt_chunk` is not empty before setting
it on `txt_records`

PR-URL: https://github.com/iojs/io.js/pull/960
Reviewed-By: Rod Vagg <rod@vagg.org>
src/cares_wrap.cc
test/internet/test-dns-txt-sigsegv.js [new file with mode: 0644]

index 373675f..c73f8c0 100644 (file)
@@ -611,8 +611,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);
 
diff --git a/test/internet/test-dns-txt-sigsegv.js b/test/internet/test-dns-txt-sigsegv.js
new file mode 100644 (file)
index 0000000..75d34c2
--- /dev/null
@@ -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);
+});