fuzz_configfile.py 901 B

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