From: Bob Halley Date: Fri, 2 Dec 2016 15:22:23 +0000 (-0800) Subject: Slighly improve ECS masking. X-Git-Tag: v1.16.0~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9a96be0698429eeea5a5efb89b31e8f6deffffc;p=thirdparty%2Fdnspython.git Slighly improve ECS masking. --- diff --git a/dns/edns.py b/dns/edns.py index 83b9be68..3a668826 100644 --- a/dns/edns.py +++ b/dns/edns.py @@ -176,10 +176,10 @@ class ECSOption(Option): # Truncate to srclen and pad to the end of the last octet needed # See RFC section 6 self.addrdata = addrdata[:nbytes] - last = chr(ord(self.addrdata[-1:]) & (0xff << srclen % 8)) - if sys.version_info >= (3,): - last = last.encode('latin1') - self.addrdata = self.addrdata[:-1] + last + nbits = srclen % 8 + if nbits != 0: + last = struct.pack('B', ord(self.addrdata[-1:]) & (0xff << nbits)) + self.addrdata = self.addrdata[:-1] + last def to_text(self): return "ECS %s/%s scope/%s" % (self.address, self.srclen,