Skip to content

Commit

Permalink
Auto-fuzz: Fix bug for illegal java class name (#965)
Browse files Browse the repository at this point in the history
* Fix bug for illegal java class name

Signed-off-by: Arthur Chan <[email protected]>

* Fix formatting

Signed-off-by: Arthur Chan <[email protected]>

---------

Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Apr 4, 2023
1 parent f7591b4 commit 230e5ae
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions tools/auto-fuzz/base_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def gen_builder_1_jvm():
BUILD_CLASSPATH=$BUILD_CLASSPATH:$JAZZER_API_PATH:$OUT/commons-lang3-3.12.0.jar
RUNTIME_CLASSPATH=$RUNTIME_CLASSPATH:\$this_dir/commons-lang3-3.12.0.jar:\$this_dir
for fuzzer in $(find $SRC -name 'Fuzz1*.java')
for fuzzer in $(find $SRC -name 'Fuzz*.java')
do
fuzzer_basename=$(basename -s .java $fuzzer)
javac -cp $BUILD_CLASSPATH $fuzzer
Expand Down Expand Up @@ -259,7 +259,7 @@ def gen_base_fuzzer_jvm():
BASE_FUZZER = """import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import org.apache.commons.lang3.ArrayUtils;
/*IMPORTS*/
public class Fuzz1/*COUNTER*/ {
public class Fuzz/*COUNTER*/ {
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
/*STATIC_OBJECT_CHOICE*/
/*CODE*/
Expand Down
2 changes: 1 addition & 1 deletion tools/auto-fuzz/fuzz_driver_generation_jvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ def generate_possible_targets(proj_folder, max_target, param_combination):

# Read the Fuzz Introspector generated data
yaml_file = os.path.join(proj_folder, "work",
"fuzzerLogFile-Fuzz1.data.yaml")
"fuzzerLogFile-Fuzz.data.yaml")
with open(yaml_file, "r") as stream:
yaml_dict = yaml.safe_load(stream)

Expand Down
22 changes: 10 additions & 12 deletions tools/auto-fuzz/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def base_fuzzer(self):
if self.language == "python":
return self.project_folder + "/fuzz_1.py"
elif self.language == "jvm":
return self.project_folder + "/Fuzz1.java"
return self.project_folder + "/Fuzz.java"
else:
# Temporary fail safe logic
return self.project_folder + "/fuzz_1.py"
Expand Down Expand Up @@ -451,7 +451,7 @@ def run_static_analysis_jvm(git_repo, basedir, project_name):
f.write(response.content)

# Retrieve path of all jar files
jarfiles.append(os.path.abspath("../Fuzz1.jar"))
jarfiles.append(os.path.abspath("../Fuzz.jar"))
jarfiles.append("%s/*.jar" % jardir)
if project_type == "ant":
for file in os.listdir(os.path.join(builddir, "build", "jar")):
Expand All @@ -467,8 +467,8 @@ def run_static_analysis_jvm(git_repo, basedir, project_name):

# Compile and package fuzzer to jar file
cmd = [
"javac -cp jazzer_standalone.jar:commons-lang3.jar:%s ../Fuzz1.java" %
":".join(jarfiles), "jar cvf ../Fuzz1.jar ../Fuzz1.class"
"javac -cp jazzer_standalone.jar:commons-lang3.jar:%s ../Fuzz.java" %
":".join(jarfiles), "jar cvf ../Fuzz.jar ../Fuzz.class"
]
try:
subprocess.check_call(" && ".join(cmd),
Expand All @@ -477,13 +477,11 @@ def run_static_analysis_jvm(git_repo, basedir, project_name):
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
except subprocess.TimeoutExpired:
print("Fail to compile Fuzz1.java.\n")
print("Fail to compile Fuzz.java.\n")
return False

# Run the java frontend static analysis
cmd = [
"./run.sh", "--jarfile", ":".join(jarfiles), "--entryclass", "Fuzz1"
]
cmd = ["./run.sh", "--jarfile", ":".join(jarfiles), "--entryclass", "Fuzz"]
try:
subprocess.check_call(" ".join(cmd),
shell=True,
Expand All @@ -500,11 +498,11 @@ def run_static_analysis_jvm(git_repo, basedir, project_name):

# Move data and data.yaml to working directory
data_src = os.path.join(os.path.dirname(FUZZ_INTRO_MAIN["jvm"]),
"fuzzerLogFile-Fuzz1.data")
"fuzzerLogFile-Fuzz.data")
yaml_src = os.path.join(os.path.dirname(FUZZ_INTRO_MAIN["jvm"]),
"fuzzerLogFile-Fuzz1.data.yaml")
data_dst = os.path.join(basedir, "work", "fuzzerLogFile-Fuzz1.data")
yaml_dst = os.path.join(basedir, "work", "fuzzerLogFile-Fuzz1.data.yaml")
"fuzzerLogFile-Fuzz.data.yaml")
data_dst = os.path.join(basedir, "work", "fuzzerLogFile-Fuzz.data")
yaml_dst = os.path.join(basedir, "work", "fuzzerLogFile-Fuzz.data.yaml")
if os.path.isfile(data_src) and os.path.isfile(yaml_src):
ret = True
try:
Expand Down
6 changes: 3 additions & 3 deletions tools/auto-fuzz/post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,16 @@ def _merge_runs(trial_dir, successful_runs, language):
shutil.copyfile(src_file, dst_file)
elif language == "jvm":
# Copy over the fuzzer for java project
src_file = os.path.join(trial_dir, run['name'], "Fuzz1.java")
dst_file = os.path.join(next_merged_dir, "Fuzz1-%d.java" % (idx))
src_file = os.path.join(trial_dir, run['name'], "Fuzz.java")
dst_file = os.path.join(next_merged_dir, "Fuzz%d.java" % (idx))

# Read in the content of the original Fuzz1.java, changing
# the class name to the new one and write the content to
# the new destination with new file name.
with open(src_file, "r") as fin:
with open(dst_file, "w") as fout:
for line in fin:
fout.write(line.replace('/*COUNTER*/', '-%d' % (idx)))
fout.write(line.replace('/*COUNTER*/', '%d' % (idx)))

idx += 1

Expand Down

0 comments on commit 230e5ae

Please sign in to comment.