|
27 | 27 | from returns.maybe import Maybe, Nothing, Some |
28 | 28 | from command_util import run_command_fuzz_all_targets as run_command |
29 | 29 |
|
30 | | -# def run_command( |
31 | | -# cmd: str, |
32 | | -# log_msg: str, |
33 | | -# logger: logging.Logger, |
34 | | -# allowed_exit_codes: Maybe[list[int]] = Nothing, |
35 | | -# timeout: int = 3600 # Default 1-hour timeout |
36 | | -# ) -> bool: |
37 | | -# """Execute commands with real-time logging and precise error handling""" |
38 | | -# allowed_codes = allowed_exit_codes.value_or([]) |
39 | | -# logger.info(f"▶️ {log_msg}...") |
40 | | -# logger.debug(f" $ {cmd}") |
41 | | - |
42 | | -# process = None |
43 | | -# try: |
44 | | -# process = subprocess.Popen( |
45 | | -# cmd, |
46 | | -# shell=True, |
47 | | -# stdout=subprocess.PIPE, |
48 | | -# stderr=subprocess.STDOUT, |
49 | | -# text=True, |
50 | | -# encoding="utf-8", |
51 | | -# errors="replace" |
52 | | -# ) |
53 | | - |
54 | | -# start_time = time.time() |
55 | | -# while process.poll() is None: |
56 | | -# if time.time() - start_time > timeout: |
57 | | -# logger.error(f"⌛ Command timed out after {timeout} seconds") |
58 | | -# process.terminate() |
59 | | -# try: |
60 | | -# process.wait(timeout=5) |
61 | | -# except subprocess.TimeoutExpired: |
62 | | -# process.kill() |
63 | | -# return False |
64 | | - |
65 | | -# if process.stdout: |
66 | | -# line = process.stdout.readline() |
67 | | -# if line: |
68 | | -# logger.debug(line.strip()) |
69 | | -# else: |
70 | | -# time.sleep(0.1) |
71 | | - |
72 | | -# exit_code = process.returncode |
73 | | -# if exit_code not in [0, *allowed_codes]: |
74 | | -# logger.error(f"❌ Command execution failed, exit code: {exit_code}") |
75 | | -# return False |
76 | | -# return True |
77 | | - |
78 | | -# except FileNotFoundError: |
79 | | -# logger.error(f"🔍 Command not found: {cmd.split()[0]}") |
80 | | -# return False |
81 | | -# except PermissionError: |
82 | | -# logger.error(f"🔒 Insufficient permissions to execute command: {cmd}") |
83 | | -# return False |
84 | | -# except subprocess.SubprocessError as e: |
85 | | -# logger.exception(f"💥 Subprocess error: {e}") |
86 | | -# return False |
87 | | -# except OSError as e: |
88 | | -# logger.exception(f"💥 Operating system error during command execution: {e}") |
89 | | -# return False |
90 | | -# finally: |
91 | | -# if process and process.poll() is None: |
92 | | -# try: |
93 | | -# process.terminate() |
94 | | -# process.wait(timeout=5) |
95 | | -# except Exception: |
96 | | -# pass |
97 | | - |
98 | | - |
99 | 30 | def discover_targets(project_name: str, oss_fuzz_dir: Path, logger: logging.Logger) -> list[str]: |
100 | 31 | """Discover fuzz targets for a project (starting with 'fuzz_', no extension, and executable)""" |
101 | 32 | out_dir = oss_fuzz_dir / "build" / "out" / project_name |
|
0 commit comments