From 49abc1df2b6c680c68d1f8240161aa52dec2c041 Mon Sep 17 00:00:00 2001 From: Enrico Pozzobon Date: Tue, 26 Mar 2019 16:34:00 +0100 Subject: [PATCH] fixed KeyError on timessent in sndrcv when an error happens during a send --- scapy/contrib/isotp.py | 2 +- scapy/contrib/isotp.uts | 51 +++++++++++++++++++++++++++++++++++++++++ scapy/sendrecv.py | 3 ++- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/scapy/contrib/isotp.py b/scapy/contrib/isotp.py index 82fff6a210b..8784dc889ac 100644 --- a/scapy/contrib/isotp.py +++ b/scapy/contrib/isotp.py @@ -643,7 +643,7 @@ def recv(self, x=0xffff): return msg @staticmethod - def select(sockets, remain=None): + def select(sockets, remain=conf.recv_poll_rate): """This function is called during sendrecv() routine to wait for sockets to be ready to receive """ diff --git a/scapy/contrib/isotp.uts b/scapy/contrib/isotp.uts index 53d2502ce59..dfdafe31658 100644 --- a/scapy/contrib/isotp.uts +++ b/scapy/contrib/isotp.uts @@ -1124,6 +1124,57 @@ assert(sent) assert(rx2 is not None) assert(rx2 == msg) + += ISOTPSoftSocket sr1 timeout with short frame +~ needs_root linux + +evt = threading.Event() +msg = ISOTP(b'\x11\x22\x33') +rx = None +finished = False + +def sender(): + global evt, rx, msg, finished + with ISOTPSoftSocket(new_can_socket(iface0), 0x123, 0x321) as sock: + evt.set() + rx = sock.sr1(msg, timeout=0.1, verbose=True) + finished = True + +txThread = threading.Thread(target=sender) +txThread.start() + +evt.wait() +txThread.join(5) + +assert(rx is None) +assert(finished) + + + += ISOTPSoftSocket sr1 timeout with long frame +~ needs_root linux + +evt = threading.Event() +msg = ISOTP(b'\x11\x22\x33\x11\x22\x33\x11\x22\x33\x11\x22\x33') +rx = None +finished = False + +def sender(): + global evt, rx, msg, finished + with ISOTPSoftSocket(new_can_socket(iface0), 0x123, 0x321) as sock: + evt.set() + rx = sock.sr1(msg, timeout=0.1, verbose=True) + finished = True + +txThread = threading.Thread(target=sender) +txThread.start() + +evt.wait() +txThread.join(5) + +assert(rx is None) +assert(finished) + = ISOTPSoftSocket sr1 and ISOTP test vice versa ~ needs_root linux diff --git a/scapy/sendrecv.py b/scapy/sendrecv.py index 2c6a713ecbf..fcc339857b5 100644 --- a/scapy/sendrecv.py +++ b/scapy/sendrecv.py @@ -229,7 +229,8 @@ def sndrcv(pks, pkt, timeout=None, inter=0, verbose=None, chainCC=False, if listable: i = 0 for p in (pkt if isinstance(pkt, list) else [pkt]): - p.sent_time = timessent[i] + if i in timessent: + p.sent_time = timessent[i] i += 1 if store_unanswered: