Skip to content

Commit 48cadcb

Browse files
committed
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: #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]>
1 parent f4f8ec2 commit 48cadcb

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/cares_wrap.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,8 @@ int ParseTxtReply(Environment* env,
904904
uint32_t i = 0, j;
905905
uint32_t offset = ret->Length();
906906
for (j = 0; current != nullptr; current = current->next) {
907-
Local<String> txt = OneByteString(env->isolate(), current->txt);
907+
Local<String> txt =
908+
OneByteString(env->isolate(), current->txt, current->length);
908909

909910
// New record found - write out the current chunk
910911
if (current->record_start) {

test/parallel/test-dns-resolveany.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const answers = [
1111
{ type: 'AAAA', address: '::42', ttl: 123 },
1212
{ type: 'MX', priority: 42, exchange: 'foobar.com', ttl: 124 },
1313
{ type: 'NS', value: 'foobar.org', ttl: 457 },
14-
{ type: 'TXT', entries: [ 'v=spf1 ~all', 'xyz' ] },
14+
{ type: 'TXT', entries: [ 'v=spf1 ~all', 'xyz\0foo' ] },
1515
{ type: 'PTR', value: 'baz.org', ttl: 987 },
1616
{
1717
type: 'SOA',

0 commit comments

Comments
 (0)