fuzz_configfile.py 870 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  2. import sys
  3. from io import BytesIO
  4. import atheris
  5. from test_utils import is_expected_exception
  6. with atheris.instrument_imports():
  7. from dulwich.config import ConfigFile
  8. def TestOneInput(data) -> int | None:
  9. try:
  10. ConfigFile.from_file(BytesIO(data))
  11. except ValueError as e:
  12. expected_exceptions = [
  13. "without section",
  14. "invalid variable name",
  15. "expected trailing ]",
  16. "invalid section name",
  17. "Invalid subsection",
  18. "escape character",
  19. "missing end quote",
  20. ]
  21. if is_expected_exception(expected_exceptions, e):
  22. return -1
  23. else:
  24. raise e
  25. def main() -> None:
  26. atheris.Setup(sys.argv, TestOneInput)
  27. atheris.Fuzz()
  28. if __name__ == "__main__":
  29. main()