From 2c8efc776c3f4dd763d5a61e517ec72577232591 Mon Sep 17 00:00:00 2001 From: timkar5 Date: Fri, 5 Dec 2025 14:08:50 +0100 Subject: [PATCH] k --- .sonar/.sonar_lock | 0 .sonar/report-task.txt | 6 ++++++ fuzzing/fuzz-targets/fuzz_config.py | 27 ++++++++++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 .sonar/.sonar_lock create mode 100644 .sonar/report-task.txt diff --git a/.sonar/.sonar_lock b/.sonar/.sonar_lock new file mode 100644 index 000000000..e69de29bb diff --git a/.sonar/report-task.txt b/.sonar/report-task.txt new file mode 100644 index 000000000..5b7115883 --- /dev/null +++ b/.sonar/report-task.txt @@ -0,0 +1,6 @@ +projectKey=gitpython +serverUrl=http://localhost:9000 +serverVersion=25.11.0.114957 +dashboardUrl=http://localhost:9000/dashboard?id=gitpython +ceTaskId=2995a1e0-8d5e-4084-ab1f-43394b167529 +ceTaskUrl=http://localhost:9000/api/ce/task?id=2995a1e0-8d5e-4084-ab1f-43394b167529 diff --git a/fuzzing/fuzz-targets/fuzz_config.py b/fuzzing/fuzz-targets/fuzz_config.py index 4eddc32ff..80b8f3ac1 100644 --- a/fuzzing/fuzz-targets/fuzz_config.py +++ b/fuzzing/fuzz-targets/fuzz_config.py @@ -30,6 +30,22 @@ with atheris.instrument_imports(): import git +def handle_fuzz_exception(e): + """Handle all expected exceptions from git_config.read().""" + # Expected config parsing-related errors → reject input. + if isinstance(e, (MissingSectionHeaderError, ParsingError, UnicodeDecodeError)): + return -1 + + # Special-case ValueError coming from embedded null bytes. + if isinstance(e, ValueError): + if "embedded null byte" in str(e): + return -1 + # Any other ValueError is unexpected → re-raise. + raise e + + # Any other exception type is unexpected → re-raise. + raise e + def TestOneInput(data): sio = io.BytesIO(data) @@ -37,15 +53,8 @@ def TestOneInput(data): git_config = git.GitConfigParser(sio) try: git_config.read() - except (MissingSectionHeaderError, ParsingError, UnicodeDecodeError): - return -1 # Reject inputs raising expected exceptions - except ValueError as e: - if "embedded null byte" in str(e): - # The `os.path.expanduser` function, which does not accept strings - # containing null bytes might raise this. - return -1 - else: - raise e # Raise unanticipated exceptions as they might be bugs + except Exception as e: + return handle_fuzz_exception(e) def main():