Bitwise AND should be with decimal 31 to also compare QR flag.

The original version of pyminifakedns ignored the value of the
Query/Response Flag ("QR flag"), which is the bit immediately prior to
the DNS opcode field. The value of the QR flag should be checked for the
value 0 along with the opcode bits, which should also be zero.
This commit is contained in:
Meitar M 2020-03-14 02:45:50 -04:00
parent bee1a38d05
commit ec37d317c9
No known key found for this signature in database
GPG key ID: 07EFAA28AB94BC85

View file

@ -96,15 +96,15 @@ class DNSQuery:
# 000 0 0000
#
# To test for this reliably, we do a bitwise AND with a value
# of decimal 15, which is 1111 in binary, exactly four bits:
# of decimal 31, which is 11111 in binary, exactly five bits:
#
# 00000000 (Remember, 0 AND 1 equals 0.)
# AND 00001111
# AND 00011111
# ------------
# 00000000 = decimal 0
#
# In one line of Python code, we get the following:
kind = (flags[0] >> 3) & 15 # Opcode is in bits 4, 5, 6, and 7 of first byte.
kind = (flags[0] >> 3) & 31 # Opcode is in bits 4, 5, 6, and 7 of first byte.
# QR bit is 8th bit, but it should be 0.
# And now, we test to see if the result
if 0 == kind: # was a standard query.