Skip to content

Commit 617920f

Browse files
Neurocineticsguedou
authored andcommitted
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...
1 parent f61f98f commit 617920f

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

scapy/layers/ntp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def haslayer(self, cls):
214214
if cls == "NTP":
215215
if isinstance(self, NTP):
216216
return True
217-
elif issubclass(cls, NTP):
217+
elif not isinstance(cls, str) and issubclass(cls, NTP):
218218
if isinstance(self, cls):
219219
return True
220220
return super(NTP, self).haslayer(cls)

test/regression.uts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7053,7 +7053,6 @@ assert(not NTPControl in p)
70537053
assert(NTPPrivate in p)
70547054
assert(NTP in p)
70557055

7056-
70577056
= NTP - Layers (2)
70587057
p = NTPHeader()
70597058
assert(type(p[NTP]) == NTPHeader)
@@ -7062,6 +7061,17 @@ assert(type(p[NTP]) == NTPControl)
70627061
p = NTPPrivate()
70637062
assert(type(p[NTP]) == NTPPrivate)
70647063

7064+
= NTP - sessions (1)
7065+
p = IP()/TCP()/NTP()
7066+
l = PacketList(p)
7067+
s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e
7068+
assert len(s) == 1
7069+
7070+
= NTP - sessions (2)
7071+
p = IP()/UDP()/NTP()
7072+
l = PacketList(p)
7073+
s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e
7074+
assert len(s) == 1
70657075

70667076
############
70677077
############

0 commit comments

Comments
 (0)