Skip to content

Commit

Permalink
dns: use length for building TXT string
Browse files Browse the repository at this point in the history
Rely on the length reported by C-Ares rather than `\0`-termination
for creating the JS string for a dns TXT response.

Fixes: #30688

PR-URL: #30690
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Nov 30, 2019
1 parent 099d3fd commit f37450f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> txt = OneByteString(env->isolate(), current->txt);
Local<String> txt =
OneByteString(env->isolate(), current->txt, current->length);

// New record found - write out the current chunk
if (current->record_start) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dns-resolveany.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f37450f

Please sign in to comment.