Skip to content

Commit

Permalink
Add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Nov 10, 2023
1 parent 1e0bc5d commit e25dcc3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/elf/fuzzing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit e25dcc3

Please sign in to comment.