Coverage for /pythoncovmergedfiles/medio/medio/src/fuzzing/projects/pycups/fuzzer/fuzz_print_job.py: 28%

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

43 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#!/usr/bin/python3 

13import sys 

14import atheris 

15import cups 

16 

17def TestOneInput(data: bytes): 

18 if len(data) < 8: 

19 return 

20 

21 fdp = atheris.FuzzedDataProvider(data) 

22 

23 try: 

24 conn = cups.Connection() 

25 

26 #generating the fuzzed parameters 

27 printer = fdp.ConsumeUnicodeNoSurrogates(64) 

28 filename = fdp.ConsumeUnicodeNoSurrogates(128) 

29 title = fdp.ConsumeUnicodeNoSurrogates(64) 

30 

31 #building fuzzed options dict 

32 options = {} 

33 num_opts = fdp.ConsumeIntInRange(0, 5) 

34 for i in range(num_opts): 

35 if fdp.remaining_bytes() < 4: 

36 break 

37 key = fdp.ConsumeUnicodeNoSurrogates(32) 

38 val = fdp.ConsumeUnicodeNoSurrogates(64) 

39 if key: #skip any empty keys 

40 options[key] = val 

41 

42 #calling the target 

43 conn.printFile(printer, filename, title, options) 

44 

45 except cups.IPPError: 

46 pass 

47 except RuntimeError: 

48 pass 

49 except Exception: 

50 pass 

51 

52def main(): 

53 atheris.instrument_all() 

54 atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) 

55 atheris.Fuzz() 

56 

57if __name__ == "__main__": 

58 main()