This commit is contained in:
Kovid Goyal 2014-07-15 13:43:30 +05:30
commit 245050d593

View File

@ -199,6 +199,9 @@ def address_type(address):
# Exceptions # Exceptions
class MalformedPacketException(Exception):
pass
class NonLocalNameException(Exception): class NonLocalNameException(Exception):
pass pass
@ -595,23 +598,26 @@ class DNSIncoming(object):
first = off first = off
while 1: while 1:
len = ord(self.data[off]) try:
off += 1 len = ord(self.data[off])
if len == 0: off += 1
break if len == 0:
t = len & 0xC0 break
if t == 0x00: t = len & 0xC0
result = ''.join((result, self.readUTF(off, len) + '.')) if t == 0x00:
off += len result = ''.join((result, self.readUTF(off, len) + '.'))
elif t == 0xC0: off += len
if next < 0: elif t == 0xC0:
next = off + 1 if next < 0:
off = ((len & 0x3F) << 8) | ord(self.data[off]) next = off + 1
if off >= first: off = ((len & 0x3F) << 8) | ord(self.data[off])
raise BadDomainNameCircular(off) if off >= first:
first = off raise BadDomainNameCircular(off)
else: first = off
raise BadDomainName(off) else:
raise BadDomainName(off)
except IndexError:
raise MalformedPacketException()
if next >= 0: if next >= 0:
self.offset = next self.offset = next
@ -876,6 +882,8 @@ class Engine(threading.Thread):
for sock in rr: for sock in rr:
try: try:
self.readers[sock].handle_read() self.readers[sock].handle_read()
except MalformedPacketException:
pass
except: except:
if DEBUG: if DEBUG:
traceback.print_exc() traceback.print_exc()