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 <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and targos committed Dec 5, 2019
1 parent d6c211d commit 053c179
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 @@ -906,7 +906,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 053c179

Please sign in to comment.