fuzz_configfile.py 886 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import sys
  2. from io import BytesIO
  3. import atheris
  4. with atheris.instrument_imports():
  5. from dulwich.config import ConfigFile
  6. def is_expected_error(error_list, error_msg):
  7. for error in error_list:
  8. if error in error_msg:
  9. return True
  10. return False
  11. def TestOneInput(data):
  12. try:
  13. ConfigFile.from_file(BytesIO(data))
  14. except ValueError as e:
  15. expected_errors = [
  16. "without section",
  17. "invalid variable name",
  18. "expected trailing ]",
  19. "invalid section name",
  20. "Invalid subsection",
  21. "escape character",
  22. "missing end quote",
  23. ]
  24. if is_expected_error(expected_errors, str(e)):
  25. return -1
  26. else:
  27. raise e
  28. def main():
  29. atheris.Setup(sys.argv, TestOneInput)
  30. atheris.Fuzz()
  31. if __name__ == "__main__":
  32. main()