From e25dcc3f90158ff5da1b8ce6f515f757a628b189 Mon Sep 17 00:00:00 2001 From: Romain Thomas Date: Fri, 10 Nov 2023 06:00:14 +0100 Subject: [PATCH] Add timeout --- tests/elf/fuzzing.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/elf/fuzzing.py b/tests/elf/fuzzing.py index a12b0ed440..087b46dc6a 100644 --- a/tests/elf/fuzzing.py +++ b/tests/elf/fuzzing.py @@ -8,6 +8,8 @@ from pathlib import Path from utils import is_linux, is_x86_64 +DEFAULT_TIMEOUT = 60 # sec + def generate_samples(melkor, seed='/usr/bin/ls', nb=100): cmd = [melkor, '-A', seed, '-n', str(nb), '-q'] @@ -41,13 +43,17 @@ def fuzz(melkor, seed, nb): continue print(f"Trying to parse {file!s}") - subprocess.check_call( - ( - sys.executable, "-c", - f"import lief;lief.logging.disable();lief.parse('{file.as_posix()}')" - ), - env=os.environ.copy() - ) + try: + subprocess.check_call( + ( + sys.executable, "-c", + f"import lief;lief.logging.disable();lief.parse('{file.as_posix()}')" + ), + timeout=DEFAULT_TIMEOUT, + env=os.environ.copy() + ) + except subprocess.TimeoutExpired: + print("Timeout!") if __name__ == '__main__': if not is_linux() and not is_x86_64():