Skip to content

Commit f37450f

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 099d3fd commit f37450f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

‎src/cares_wrap.cc‎

Lines changed: 2 additions & 1 deletion
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‎

Lines changed: 1 addition & 1 deletion
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)