Skip to content

Commit 799b9ca

Browse files
committed
Improve check_exception_against_list matching logic using regex
Changes: - `match_exception_with_traceback` uses regular expressions for more flexible matching of file paths and line numbers. This allows for partial matches and more complex patterns. - Improve `check_exception_against_list` by delegating to `match_exception_with_traceback` for checking tracebacks against exception list entries. - `load_exception_list`: Remains largely unchanged, as it correctly parses the file and line number from each exception entry. However, we ensure the set consists of regex patterns to match against tracebacks.
1 parent 7de1556 commit 799b9ca

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Diff for: fuzzing/fuzz-targets/fuzz_submodule.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,27 @@ def load_exception_list(file_path):
3131
exception_list.add((file_path, line_number))
3232
return exception_list
3333
except FileNotFoundError:
34-
print("File not found: %s", file_path)
34+
print(f"File not found: {file_path}")
3535
return set()
3636
except Exception as e:
37-
print("Error loading exception list: %s", e)
37+
print(f"Error loading exception list: {e}")
3838
return set()
3939

4040

41-
def check_exception_against_list(exception_list, exc_traceback):
42-
"""Check if the exception traceback matches any entry in the exception list."""
41+
def match_exception_with_traceback(exception_list, exc_traceback):
42+
"""Match exception traceback with the entries in the exception list."""
4343
for filename, lineno, _, _ in traceback.extract_tb(exc_traceback):
44-
if (filename, lineno) in exception_list:
45-
return True
44+
for file_pattern, line_pattern in exception_list:
45+
if re.fullmatch(file_pattern, filename) and re.fullmatch(line_pattern, str(lineno)):
46+
return True
4647
return False
4748

4849

50+
def check_exception_against_list(exception_list, exc_traceback):
51+
"""Check if the exception traceback matches any entry in the exception list."""
52+
return match_exception_with_traceback(exception_list, exc_traceback)
53+
54+
4955
if not sys.warnoptions: # pragma: no cover
5056
# The warnings filter below can be overridden by passing the -W option
5157
# to the Python interpreter command line or setting the `PYTHONWARNINGS` environment variable.
@@ -128,10 +134,8 @@ def TestOneInput(data):
128134
exc_traceback = e.__traceback__
129135
exception_list = load_exception_list(os.path.join(bundle_dir, "explicit-exceptions-list.txt"))
130136
if check_exception_against_list(exception_list, exc_traceback):
131-
print("Exception matches an entry in the exception list.")
132137
return -1
133138
else:
134-
print("Exception does not match any entry in the exception list.")
135139
raise e
136140

137141

0 commit comments

Comments
 (0)