5
5
This module contains fuzz testing for the RParser's handling of renv.lock files.
6
6
"""
7
7
8
+ import os
9
+ import shutil
8
10
import sys
9
11
import tempfile
10
- from pathlib import Path
11
12
12
13
import atheris
13
14
import atheris_libprotobuf_mutator
25
26
logger = LOGGER .getChild ("Fuzz" )
26
27
27
28
28
- def RenvLockBuilder (data ):
29
+ def RenvLockBuilder (data , file_path ):
29
30
"""
30
31
This function converts the given data into a renv.lock file.
31
32
32
33
Args:
33
34
data (protobuf message): The protobuf message to convert and process.
35
+ file_path: The path of the file to build.
34
36
"""
35
37
# Parse the JSON data
36
38
json_data = MessageToDict (
@@ -89,13 +91,16 @@ def RenvLockBuilder(data):
89
91
f .write ("}\n " )
90
92
91
93
92
- def TestParseData (data ):
94
+ def TestParseData (data , cve_db , logger , tmpdir ):
93
95
"""
94
- Fuzz testing function for the RParser's handling of renv.lock files.
95
-
96
+ Fuzz test the RustParser's handling of renv.lock files.
96
97
Args:
97
- data (protobuf message): The protobuf message to convert and process.
98
+ data (protobuf message): The protobuf message to convert to a renv.lock file.
99
+ cve_db: Object for the Database of CVE-BIN-TOOL.
100
+ logger: Logger object.
101
+ tmpdir: The temporary direct object.
98
102
"""
103
+ file_path = os .path .join (tmpdir , "renv.lock" )
99
104
try :
100
105
RenvLockBuilder (data )
101
106
@@ -106,7 +111,20 @@ def TestParseData(data):
106
111
return
107
112
108
113
109
- file_path = str (Path (tempfile .mkdtemp (prefix = "cve-bin-tool-" )) / "renv.lock" )
110
-
111
- atheris_libprotobuf_mutator .Setup (sys .argv , TestParseData , proto = renv_lock_pb2 .RenvLock )
112
- atheris .Fuzz ()
114
+ def main ():
115
+ """Main Function to Run Fuzzing and Facilitate Tempfile cleanup."""
116
+ tmpdir = tempfile .mkdtemp (prefix = "cve-bin-tool-fuzz-renv-" )
117
+ try :
118
+ atheris_libprotobuf_mutator .Setup (
119
+ sys .argv ,
120
+ lambda data : TestParseData (data , cve_db , logger , tmpdir ),
121
+ proto = renv_lock_pb2 .RenvLock ,
122
+ )
123
+ atheris .Fuzz ()
124
+ finally :
125
+ if os .path .exists (tmpdir ):
126
+ shutil .rmtree (tmpdir )
127
+
128
+
129
+ if __name__ == "__main__" :
130
+ main ()
0 commit comments