Skip to content

Commit 0631504

Browse files
committed
modify
1 parent e0c7740 commit 0631504

2 files changed

Lines changed: 108 additions & 110 deletions

File tree

fuzz/build_fuzzers.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,53 @@
2727
from typing import Optional
2828
from multiprocessing import Pool, cpu_count
2929
from errors import BuildError, CommandError, PathError, ConfigError
30-
31-
def run_command(
32-
cmd: str,
33-
oss_fuzz_dir: Path,
34-
project: str = "",
35-
allowed_exit_codes: Optional[list[int]] = None
36-
) -> int:
37-
"""Execute a command and return the exit code"""
38-
allowed_exit_codes = allowed_exit_codes or [0]
39-
logging.info(f"▶️ Executing command: {cmd}")
30+
from command_util import run_command_build_fuzz as run_command
31+
32+
# def run_command(
33+
# cmd: str,
34+
# oss_fuzz_dir: Path,
35+
# project: str = "",
36+
# allowed_exit_codes: Optional[list[int]] = None
37+
# ) -> int:
38+
# """Execute a command and return the exit code"""
39+
# allowed_exit_codes = allowed_exit_codes or [0]
40+
# logging.info(f"▶️ Executing command: {cmd}")
4041

41-
try:
42-
process = subprocess.Popen(
43-
cmd,
44-
shell=True,
45-
cwd=str(oss_fuzz_dir),
46-
stdout=subprocess.PIPE,
47-
stderr=subprocess.PIPE,
48-
text=True
49-
)
42+
# try:
43+
# process = subprocess.Popen(
44+
# cmd,
45+
# shell=True,
46+
# cwd=str(oss_fuzz_dir),
47+
# stdout=subprocess.PIPE,
48+
# stderr=subprocess.PIPE,
49+
# text=True
50+
# )
5051

51-
stdout, stderr = process.communicate()
52-
exit_code = process.returncode
52+
# stdout, stderr = process.communicate()
53+
# exit_code = process.returncode
5354

54-
if exit_code in allowed_exit_codes:
55-
return exit_code
55+
# if exit_code in allowed_exit_codes:
56+
# return exit_code
5657

57-
# Build detailed error message
58-
error_msg = f"Command failed (exit code: {exit_code})"
59-
if project:
60-
error_msg += f" for project: {project}"
58+
# # Build detailed error message
59+
# error_msg = f"Command failed (exit code: {exit_code})"
60+
# if project:
61+
# error_msg += f" for project: {project}"
6162

62-
if stderr.strip():
63-
error_msg += f"\nError output:\n{stderr.strip()}"
63+
# if stderr.strip():
64+
# error_msg += f"\nError output:\n{stderr.strip()}"
6465

65-
if stdout.strip():
66-
error_msg += f"\nOutput:\n{stdout.strip()}"
66+
# if stdout.strip():
67+
# error_msg += f"\nOutput:\n{stdout.strip()}"
6768

68-
raise CommandError(error_msg, project=project, exit_code=exit_code)
69+
# raise CommandError(error_msg, project=project, exit_code=exit_code)
6970

70-
except FileNotFoundError as e:
71-
raise CommandError(f"Command not found: {cmd.split()[0]}", project=project) from e
72-
except OSError as e:
73-
raise CommandError(f"System error: {e}", project=project) from e
74-
except subprocess.SubprocessError as e:
75-
raise CommandError(f"Subprocess error: {e}", project=project) from e
71+
# except FileNotFoundError as e:
72+
# raise CommandError(f"Command not found: {cmd.split()[0]}", project=project) from e
73+
# except OSError as e:
74+
# raise CommandError(f"System error: {e}", project=project) from e
75+
# except subprocess.SubprocessError as e:
76+
# raise CommandError(f"Subprocess error: {e}", project=project) from e
7677

7778
def build_fuzzers(project_name: str, sanitizer: str, oss_fuzz_dir: Path) -> tuple[bool, str]:
7879
"""Fuzzer build workflow"""

fuzz/run_fuzz_all_targets.py

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

10198

10299
def discover_targets(project_name: str, oss_fuzz_dir: Path, logger: logging.Logger) -> list[str]:

0 commit comments

Comments
 (0)