i += 1
if not (c2.isdigit() and c3.isdigit()):
raise dns.exception.SyntaxError
- c = chr(int(c) * 100 + int(c2) * 10 + int(c3))
+ codepoint = int(c) * 100 + int(c2) * 10 + int(c3)
+ if codepoint > 255:
+ raise dns.exception.SyntaxError
+ c = chr(codepoint)
unescaped += c.encode()
if len(unescaped) > 0:
items.append(unescaped)
i += 1
if not (c2.isdigit() and c3.isdigit()):
raise dns.exception.SyntaxError
- c = chr(int(c) * 100 + int(c2) * 10 + int(c3))
+ codepoint = int(c) * 100 + int(c2) * 10 + int(c3)
+ if codepoint > 255:
+ raise dns.exception.SyntaxError
+ c = chr(codepoint)
unescaped += c
return Token(self.ttype, unescaped)
i += 1
if not (c2.isdigit() and c3.isdigit()):
raise dns.exception.SyntaxError
- unescaped += b'%c' % (int(c) * 100 + int(c2) * 10 + int(c3))
+ codepoint = int(c) * 100 + int(c2) * 10 + int(c3)
+ if codepoint > 255:
+ raise dns.exception.SyntaxError
+ unescaped += b'%c' % (codepoint)
else:
# Note that as mentioned above, if c is a Unicode
# code point outside of the ASCII range, then this
dns.rdata.from_text('in', 'svcb', '1 . alpn=\\00')
with self.assertRaises(dns.exception.SyntaxError):
dns.rdata.from_text('in', 'svcb', '1 . alpn=\\00q')
+ with self.assertRaises(dns.exception.SyntaxError):
+ dns.rdata.from_text('in', 'svcb', '1 . alpn=\\256')
# This doesn't usually get exercised, so we do it directly.
gp = dns.rdtypes.svcbbase.GenericParam.from_value('\\001\\002')
expected = '"\\001\\002"'
tok = dns.tokenizer.Tokenizer('\\')
tok.get()
+ def testEscapeBounds(self):
+ with self.assertRaises(dns.exception.SyntaxError):
+ tok = dns.tokenizer.Tokenizer('\\256')
+ tok.get().unescape()
+ with self.assertRaises(dns.exception.SyntaxError):
+ tok = dns.tokenizer.Tokenizer('\\256')
+ tok.get().unescape_to_bytes()
+
def testGetUngetRegetComment(self):
tok = dns.tokenizer.Tokenizer(';comment')
t1 = tok.get(want_comment=True)