From f37450f58075bcc2ec2c04fae40b874683eb418c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 27 Nov 2019 21:51:54 +0100 Subject: [PATCH] dns: use length for building TXT string Rely on the length reported by C-Ares rather than `\0`-termination for creating the JS string for a dns TXT response. Fixes: https://github.com/nodejs/node/issues/30688 PR-URL: https://github.com/nodejs/node/pull/30690 Reviewed-By: Colin Ihrig Reviewed-By: David Carlier Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- src/cares_wrap.cc | 3 ++- test/parallel/test-dns-resolveany.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 1fb0f47dd80f08..f7a02e469aa79a 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -904,7 +904,8 @@ int ParseTxtReply(Environment* env, uint32_t i = 0, j; uint32_t offset = ret->Length(); for (j = 0; current != nullptr; current = current->next) { - Local txt = OneByteString(env->isolate(), current->txt); + Local txt = + OneByteString(env->isolate(), current->txt, current->length); // New record found - write out the current chunk if (current->record_start) { diff --git a/test/parallel/test-dns-resolveany.js b/test/parallel/test-dns-resolveany.js index bb15b1a38b4ad3..33beee847fd52c 100644 --- a/test/parallel/test-dns-resolveany.js +++ b/test/parallel/test-dns-resolveany.js @@ -11,7 +11,7 @@ const answers = [ { type: 'AAAA', address: '::42', ttl: 123 }, { type: 'MX', priority: 42, exchange: 'foobar.com', ttl: 124 }, { type: 'NS', value: 'foobar.org', ttl: 457 }, - { type: 'TXT', entries: [ 'v=spf1 ~all', 'xyz' ] }, + { type: 'TXT', entries: [ 'v=spf1 ~all', 'xyz\0foo' ] }, { type: 'PTR', value: 'baz.org', ttl: 987 }, { type: 'SOA',