Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_parsing.py: 56%

36 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:45 +0000

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 

13# Copyright 2022 Google LLC 

14# 

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

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

17# You may obtain a copy of the License at 

18# 

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

20# 

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

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

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

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

25# limitations under the License. 

26 

27import sys 

28import atheris 

29 

30with atheris.instrument_imports(): 

31 from netaddr import IPAddress, IPNetwork, IPRange, AddrFormatError 

32 

33 

34def TestOneInput(data): 

35 fdp = atheris.FuzzedDataProvider(data) 

36 s1 = fdp.ConsumeString(fdp.ConsumeIntInRange(0, 1024)) 

37 s2 = fdp.ConsumeString(fdp.ConsumeIntInRange(0, 1024)) 

38 try: 

39 IPAddress(s1) 

40 IPNetwork(s1) 

41 IPRange(s1,s2) 

42 except AddrFormatError as e: 

43 None 

44 except ValueError as e: 

45 msgs = [ 

46 "is an invalid IP version", 

47 "netmasks or subnet" 

48 ] 

49 found = False 

50 for msg in msgs: 

51 if msg in str(e): 

52 found = True 

53 if not found: 

54 raise e 

55 

56 

57def main(): 

58 atheris.instrument_all() 

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

60 atheris.Fuzz() 

61 

62 

63if __name__ == "__main__": 

64 main()