Skip to content

Commit 967564e

Browse files
authored
Fix #3880: AutomotiveTestCaseExecutor on 32-bit machines (#3887)
* Fix #3880 * apply suggestions --------- Co-authored-by: Nils Weiss <[email protected]>
1 parent e04ccc6 commit 967564e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

scapy/contrib/automotive/scanner/enumerator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def execute(self, socket, state, **kwargs):
288288

289289
# log_automotive.debug("[i] Using iterator %s in state %s", it, state)
290290

291-
start_time = time.time()
291+
start_time = time.monotonic()
292292
log_automotive.debug(
293293
"Start execution of enumerator: %s", time.ctime(start_time))
294294

@@ -309,7 +309,7 @@ def execute(self, socket, state, **kwargs):
309309
"Finished execution count of enumerator")
310310
return
311311

312-
if (start_time + execution_time) < time.time():
312+
if (start_time + execution_time) < time.monotonic():
313313
log_automotive.debug(
314314
"[i] Finished execution time of enumerator: %s",
315315
time.ctime())

scapy/contrib/automotive/scanner/executor.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def execute_test_case(self, test_case, kill_time=None):
184184
test_case_kwargs = dict()
185185

186186
if kill_time:
187-
max_execution_time = max(int(kill_time - time.time()), 5)
187+
max_execution_time = max(int(kill_time - time.monotonic()), 5)
188188
cur_execution_time = test_case_kwargs.get("execution_time", 1200)
189189
test_case_kwargs["execution_time"] = min(max_execution_time,
190190
cur_execution_time)
@@ -258,16 +258,19 @@ def scan(self, timeout=None):
258258
:return: None
259259
"""
260260
self.configuration.stop_event.clear()
261-
kill_time = time.time() + (timeout or 0xffffffff)
261+
if timeout is None:
262+
kill_time = None
263+
else:
264+
kill_time = time.monotonic() + timeout
262265
log_automotive.debug("Set kill_time to %s" % time.ctime(kill_time))
263-
while kill_time > time.time():
266+
while kill_time is None or kill_time > time.monotonic():
264267
test_case_executed = False
265268
log_automotive.info("[i] Scan progress %0.2f", self.progress())
266269
log_automotive.debug("[i] Scan paths %s", self.state_paths)
267270
for p, test_case in product(
268271
self.state_paths, self.configuration.test_cases):
269272
log_automotive.info("Scan path %s", p)
270-
terminate = kill_time <= time.time()
273+
terminate = kill_time and kill_time <= time.monotonic()
271274
if terminate or self.configuration.stop_event.is_set():
272275
log_automotive.debug(
273276
"Execution time exceeded. Terminating scan!")

0 commit comments

Comments
 (0)