From: Nils Wisiol Date: Fri, 29 May 2020 10:47:38 +0000 (+0200) Subject: Check character-string length for HINFO records X-Git-Tag: v2.0.0rc1~143^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28bde999ee9b5f57c06b4761d130a193f0e51972;p=thirdparty%2Fdnspython.git Check character-string length for HINFO records --- diff --git a/dns/rdtypes/ANY/HINFO.py b/dns/rdtypes/ANY/HINFO.py index 5bc6a156..e3efb51a 100644 --- a/dns/rdtypes/ANY/HINFO.py +++ b/dns/rdtypes/ANY/HINFO.py @@ -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) diff --git a/dns/tokenizer.py b/dns/tokenizer.py index 791e9948..a13268d9 100644 --- a/dns/tokenizer.py +++ b/dns/tokenizer.py @@ -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):