From 617920fddba4af4e5d12ea38a0817abf5d192178 Mon Sep 17 00:00:00 2001 From: Neurocinetics <0901653@student.hr.nl> Date: Thu, 8 Mar 2018 12:44:44 +0100 Subject: [PATCH] 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 * https://github.com/secdev/scapy/pull/1186/files/d0a2544ae13ba353d25e86be2cfc13cceda36a10 * 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 * https://github.com/secdev/scapy/pull/1186/files/d0a2544ae13ba353d25e86be2cfc13cceda36a10 * Forgot to delete ntp.uts during rebase... --- scapy/layers/ntp.py | 2 +- test/regression.uts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scapy/layers/ntp.py b/scapy/layers/ntp.py index f8dbe16b4..5941ad4ce 100644 --- a/scapy/layers/ntp.py +++ b/scapy/layers/ntp.py @@ -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) diff --git a/test/regression.uts b/test/regression.uts index 66e62ec6f..c0b934161 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -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 ############ ############