Coverage for /pythoncovmergedfiles/medio/medio/src/gitpython/fuzzing/fuzz-targets/fuzz_config.py: 37%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

35 statements  

1###### Coverage stub 

2import atexit 

3import coverage 

4cov = coverage.coverage(data_file='.coverage', cover_pylib=True) 

5cov.start() 

6# Register an exist handler that will print coverage 

7def exit_handler(): 

8 cov.stop() 

9 cov.save() 

10atexit.register(exit_handler) 

11####### End of coverage stub 

12# Copyright 2023 Google LLC 

13# 

14# Licensed under the Apache License, Version 2.0 (the "License"); 

15# you may not use this file except in compliance with the License. 

16# You may obtain a copy of the License at 

17# 

18# http://www.apache.org/licenses/LICENSE-2.0 

19# 

20# Unless required by applicable law or agreed to in writing, software 

21# distributed under the License is distributed on an "AS IS" BASIS, 

22# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

23# See the License for the specific language governing permissions and 

24# limitations under the License. 

25# 

26############################################################################### 

27# Note: This file has been modified by contributors to GitPython. 

28# The original state of this file may be referenced here: 

29# https://github.com/google/oss-fuzz/commit/f26f254558fc48f3c9bc130b10507386b94522da 

30############################################################################### 

31import atheris 

32import sys 

33import io 

34import os 

35from configparser import MissingSectionHeaderError, ParsingError 

36 

37if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): 

38 path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git")) 

39 os.environ["GIT_PYTHON_GIT_EXECUTABLE"] = path_to_bundled_git_binary 

40 

41with atheris.instrument_imports(): 

42 import git 

43 

44 

45def TestOneInput(data): 

46 sio = io.BytesIO(data) 

47 sio.name = "/tmp/fuzzconfig.config" 

48 git_config = git.GitConfigParser(sio) 

49 try: 

50 git_config.read() 

51 except (MissingSectionHeaderError, ParsingError, UnicodeDecodeError): 

52 return -1 # Reject inputs raising expected exceptions 

53 except ValueError as e: 

54 if "embedded null byte" in str(e): 

55 # The `os.path.expanduser` function, which does not accept strings 

56 # containing null bytes might raise this. 

57 return -1 

58 else: 

59 raise e # Raise unanticipated exceptions as they might be bugs 

60 

61 

62def main(): 

63 atheris.Setup(sys.argv, TestOneInput) 

64 atheris.Fuzz() 

65 

66 

67if __name__ == "__main__": 

68 main()