Skip to content

fixed KeyError on timessent in sndrcv when an error happens during a send #1937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scapy/contrib/isotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
51 changes: 51 additions & 0 deletions scapy/contrib/isotp.uts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion scapy/sendrecv.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,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:
Expand Down