Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/typefuzz
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def main():
signal.signal(signal.SIGINT, stats_control_c)
else:
signal.signal(signal.SIGINT, silent_control_c)
exit(OK_NOBUGS)

fuzzer.run()
except Exception as e:
Expand Down
32 changes: 29 additions & 3 deletions yinyang/src/core/Fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,38 @@ def __init__(self, args, strategy):
self.first_status_bar_printed = False
self.name = random_string()
self.timeout_of_current_seed = 0
self.header_comments = "" # Store header comments to preserve in mutants

init_logging(strategy, self.args.quiet, self.name, args)

def extract_header_comments(self, seed_file):
"""
Extract header comments (lines starting with ;) that appear before
the first SMT-LIB command. These typically include EXPECT, COMMAND-LINE, etc.
"""
header = []
try:
with open(seed_file, 'r') as f:
for line in f:
stripped = line.strip()
if stripped.startswith(';'):
header.append(line.rstrip('\n'))
elif stripped and not stripped.startswith(';'):
# First non-comment, non-empty line - stop collecting headers
break
except Exception:
pass
return '\n'.join(header) + ('\n' if header else '')

def process_seed(self, seed):
if not admissible_seed_size(seed, self.args):
self.statistic.invalid_seeds += 1
logging.debug("Skip invalid seed: exceeds max file size")
return None, None

self.currentseeds.append(pathlib.Path(seed).stem)
# Extract header comments before parsing
self.header_comments = self.extract_header_comments(seed)
script, glob = parse_file(seed, silent=True)

if not script:
Expand Down Expand Up @@ -220,6 +242,9 @@ def create_testbook(self, script):
random_string(),
)
with open(testcase, "w") as testcase_writer:
# Prepend header comments if they exist
if self.header_comments:
testcase_writer.write(self.header_comments)
testcase_writer.write(script.__str__())

for cli in self.args.SOLVER_CLIS:
Expand Down Expand Up @@ -477,6 +502,7 @@ def terminate(self):
exit(OK_BUGS)

def __del__(self):
for fn in os.listdir(self.args.scratchfolder):
if self.name in fn:
os.remove(os.path.join(self.args.scratchfolder, fn))
if not self.args.keep_mutants:
for fn in os.listdir(self.args.scratchfolder):
if self.name in fn:
os.remove(os.path.join(self.args.scratchfolder, fn))
Loading