Fixed a TypeError that triggered when reading a pcap file containing a NTP packet. (#1186)

* Fixed an error (TypeError) that triggered when reading a pcap file that
contained ntp packets. The type of variable "cls" was string not a class
type (invalid argument for method: issubclass()). By importing the type
'TCP' from 'scapy.layers.inet' and by converting cls to a classtype by
reading the key from globals, the TypeError is mitigated.

* Added test to provide insight into the cls variable inconsistencies.
Fixed a small mistake

* d0a2544ae1

* Moved tests.

* fix backward incompatibility of scapy.utils.RawPcapReader.read_packet() for scapy's v2.4 againts v2.3.2 & v2.3.3
named tuple instead of tuple as result of RawPcap[Ng]Reader.read_block_???()/read_packet():

* Fixed an error (TypeError) that triggered when calling sessions() on a PacketList that
contained ntp packets. The type of variable "cls" was a string not a class
type (invalid argument for method: issubclass()).

* Added test to provide insight into the cls variable inconsistencies.
Fixed a small mistake

* d0a2544ae1

* Forgot to delete ntp.uts during rebase...
This commit is contained in:
Neurocinetics 2018-03-08 12:44:44 +01:00 committed by Guillaume Valadon
parent f61f98f807
commit 617920fddb
2 changed files with 12 additions and 2 deletions

View File

@ -214,7 +214,7 @@ class NTP(Packet):
if cls == "NTP":
if isinstance(self, NTP):
return True
elif issubclass(cls, NTP):
elif not isinstance(cls, str) and issubclass(cls, NTP):
if isinstance(self, cls):
return True
return super(NTP, self).haslayer(cls)

View File

@ -7053,7 +7053,6 @@ assert(not NTPControl in p)
assert(NTPPrivate in p)
assert(NTP in p)
= NTP - Layers (2)
p = NTPHeader()
assert(type(p[NTP]) == NTPHeader)
@ -7062,6 +7061,17 @@ assert(type(p[NTP]) == NTPControl)
p = NTPPrivate()
assert(type(p[NTP]) == NTPPrivate)
= NTP - sessions (1)
p = IP()/TCP()/NTP()
l = PacketList(p)
s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e
assert len(s) == 1
= NTP - sessions (2)
p = IP()/UDP()/NTP()
l = PacketList(p)
s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e
assert len(s) == 1
############
############