]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Check character-string length for HINFO records 494/head
authorNils Wisiol <mail@nils-wisiol.de>
Fri, 29 May 2020 10:47:38 +0000 (12:47 +0200)
committerNils Wisiol <mail@nils-wisiol.de>
Fri, 29 May 2020 10:48:27 +0000 (12:48 +0200)
dns/rdtypes/ANY/HINFO.py
dns/tokenizer.py

index 5bc6a156207d69deb8c621dcc2cfcc91c0e240a8..e3efb51aedfbda67b407159c656b01e311aea3dc 100644 (file)
@@ -48,8 +48,8 @@ class HINFO(dns.rdata.Rdata):
     @classmethod
     def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True,
                   relativize_to=None):
-        cpu = tok.get_string()
-        os = tok.get_string()
+        cpu = tok.get_string(max_length=255)
+        os = tok.get_string(max_length=255)
         tok.get_eol()
         return cls(rdclass, rdtype, cpu, os)
 
index 791e99483cca1c1e3859966812c36f8dcd39fb6d..a13268d92592abd950ff2f3d984a1cc5de86d6bd 100644 (file)
@@ -533,10 +533,12 @@ class Tokenizer(object):
                 '%d is not an unsigned 32-bit integer' % value)
         return value
 
-    def get_string(self, origin=None):
+    def get_string(self, origin=None, max_length=None):
         """Read the next token and interpret it as a string.
 
         Raises dns.exception.SyntaxError if not a string.
+        Raises dns.exception.SyntaxError if token value length
+        exceeds max_length (if specified).
 
         Returns a string.
         """
@@ -544,6 +546,8 @@ class Tokenizer(object):
         token = self.get().unescape()
         if not (token.is_identifier() or token.is_quoted_string()):
             raise dns.exception.SyntaxError('expecting a string')
+        if max_length and len(token.value) > max_length:
+            raise dns.exception.SyntaxError("string too long")
         return token.value
 
     def get_identifier(self, origin=None):