Skip to content

Commit f943b67

Browse files
committed
Fix sniffer join waiting indefinitely
When trying to stop a sniffer that was not already started, Scapy_Exception("Unsupported (offline or unsupported socket)") is no more raised and join() is waiting indefinitely. Restore the previous stop_cb behavior. Fixes: 6689da4 ("Add missing type in AsyncSniffer (secdev#4665)") Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
1 parent bd7f2a3 commit f943b67

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scapy/sendrecv.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def __init__(self, *args, **kwargs):
11501150
self.thread = None # type: Optional[Thread]
11511151
self.results = None # type: Optional[PacketList]
11521152
self.exception = None # type: Optional[Exception]
1153-
self.stop_cb = lambda: None # type: Callable[[], None]
1153+
self.stop_cb = lambda: None # type: Callable[[], Optional[bool]]
11541154

11551155
def _setup_thread(self):
11561156
# type: () -> None
@@ -1295,16 +1295,18 @@ def _run(self,
12951295
sniff_sockets[close_pipe] = "control_socket" # type: ignore
12961296

12971297
def stop_cb():
1298-
# type: () -> None
1298+
# type: () -> bool
12991299
if self.running and close_pipe:
13001300
close_pipe.send(None)
13011301
self.continue_sniff = False
1302+
return True
13021303
self.stop_cb = stop_cb
13031304
else:
13041305
# select is non blocking
13051306
def stop_cb():
1306-
# type: () -> None
1307+
# type: () -> bool
13071308
self.continue_sniff = False
1309+
return True
13081310
self.stop_cb = stop_cb
13091311

13101312
try:
@@ -1400,9 +1402,7 @@ def stop(self, join=True):
14001402
# type: (bool) -> Optional[PacketList]
14011403
"""Stops AsyncSniffer if not in async mode"""
14021404
if self.running:
1403-
try:
1404-
self.stop_cb()
1405-
except AttributeError:
1405+
if not self.stop_cb():
14061406
raise Scapy_Exception(
14071407
"Unsupported (offline or unsupported socket)"
14081408
)

0 commit comments

Comments
 (0)