Skip to content

Commit

Permalink
Merge branch '84-handle-dns-txt-records-contain-multiple-strings'
Browse files Browse the repository at this point in the history
Closes: #84
  • Loading branch information
c0r0n3r committed Mar 19, 2024
2 parents 2a7cf37 + 08787c2 commit 0ff31da
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
Changelog
=========

------
0.12.4
------

Notable fixes
=============

- DNS

- handle TXT records that contain multiple string (#84)

-------------------
0.12.3 - 2024-03-05
-------------------
Expand Down
7 changes: 5 additions & 2 deletions cryptoparser/dnsrec/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,13 @@ def _parse(cls, parsable):
raise NotEnoughData(cls.HEADER_SIZE - len(parsable))

parser = ParserBinary(parsable)
value = ''

parser.parse_string('value', 1, encoding='ascii')
while parser.unparsed_length:
parser.parse_string('value', 1, encoding='ascii')
value += parser['value']

return cls(**parser), parser.parsed_length
return cls(value), parser.parsed_length

def compose(self):
composer = ComposerBinary()
Expand Down
18 changes: 14 additions & 4 deletions test/dnsrec/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,21 @@ def test_compose(self):

class TestDnsRecordTxt(unittest.TestCase):
def setUp(self):
self.record_bytes = bytes(
self.record_bytes_single = bytes(
b'\x05' + # length: 5
b'value' +
b''
)
self.record = DnsRecordTxt(value='value')
self.record_single = DnsRecordTxt(value='value')

self.record_bytes_multiple = bytes(
b'\x06' + # length: 6
b'value1' +
b'\x06' + # length: 6
b'value2' +
b''
)
self.record_multiple = DnsRecordTxt(value='value1value2')

def test_error_not_enough_data(self):
with self.assertRaises(NotEnoughData) as context_manager:
Expand All @@ -537,7 +546,8 @@ def test_error_not_enough_data(self):
)

def test_parse(self):
self.assertEqual(DnsRecordTxt.parse_exact_size(self.record_bytes), self.record)
self.assertEqual(DnsRecordTxt.parse_exact_size(self.record_bytes_single), self.record_single)
self.assertEqual(DnsRecordTxt.parse_exact_size(self.record_bytes_multiple), self.record_multiple)

def test_compose(self):
self.assertEqual(self.record.compose(), self.record_bytes)
self.assertEqual(self.record_single.compose(), self.record_bytes_single)

0 comments on commit 0ff31da

Please sign in to comment.