Skip to content

Commit

Permalink
Flush log data when closing the test.
Browse files Browse the repository at this point in the history
jtpereyda#601
Text log file and CSV log file requires a file flush so the data is consistent with the boofuzz db file.
Amended file formatting using the results of the "black" program.
  • Loading branch information
ptdropper committed Jan 2, 2023
1 parent 5634b49 commit 5fc344c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Fixes
- Changed type of `default_value` from string to bytes for `FromFile`.
- `s_update` primitive was out of date.
- The minimum supported Python version is now 3.7.
- Flush log data when closing the test.

v0.4.1
------
Expand Down
6 changes: 5 additions & 1 deletion boofuzz/fuzz_logger_csv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import csv
import datetime
import sys

from . import helpers, ifuzz_logger_backend

Expand Down Expand Up @@ -37,6 +37,7 @@ def __init__(self, file_handle=sys.stdout, bytes_to_str=DEFAULT_HEX_TO_STR):
file_handle (io.BinaryIO): Open file handle for logging. Defaults to sys.stdout.
bytes_to_str (function): Function that converts sent/received bytes data to string for logging.
"""
file: file_handle
self._file_handle = file_handle
self._format_raw_bytes = bytes_to_str
self._csv_handle = csv.writer(self._file_handle)
Expand Down Expand Up @@ -72,6 +73,9 @@ def close_test_case(self):
pass

def close_test(self):
# At this point any buffered data in the file must be flushed to prevent loss.
# Issue 601 https://github.com/jtpereyda/boofuzz/issues/601
print("", file=self._file_handle, flush=True)
pass

def _print_log_msg(self, msg):
Expand Down
1 change: 1 addition & 0 deletions boofuzz/fuzz_logger_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ def _print_log_msg(self, msg_type, msg=None, data=None):
print(
helpers.format_log_msg(msg_type=msg_type, description=msg, data=data, indent_size=self.INDENT_SIZE),
file=self._file_handle,
flush=True,
)

0 comments on commit 5fc344c

Please sign in to comment.