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 f4f8ec2 commit 48cadcb
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 48cadcb

Please sign in to comment.