fuzz_configfile.py 842 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import sys
  2. from io import BytesIO
  3. from typing import Optional
  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) -> Optional[int]:
  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()