1#!/bin/bash -eu 2# Copyright 2021 Google LLC 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17 18# Move seed corpus and dictionary. 19mv $SRC/{*.zip,*.dict} $OUT 20 21# Build the json-sanitizer jar. 22CURRENT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \ 23-Dexpression=project.version -q -DforceStdout) 24mvn package 25cp "target/json-sanitizer-$CURRENT_VERSION.jar" $OUT/json-sanitizer.jar 26 27# The jar files containing the project (separated by spaces). 28PROJECT_JARS=json-sanitizer.jar 29 30# Get the fuzzer dependencies (gson). 31mvn dependency:copy -Dartifact=com.google.code.gson:gson:2.8.6 -DoutputDirectory=$OUT/ 32 33# The jar files containing further dependencies of the fuzz targets (separated 34# by spaces). 35FUZZER_JARS=gson-2.8.6.jar 36 37# Build fuzzers in $OUT. 38ALL_JARS="$PROJECT_JARS $FUZZER_JARS" 39BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH 40 41# All jars and class files lie in the same directory as the fuzzer at runtime. 42RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):.:\$this_dir 43 44for fuzzer in $(find $SRC -name '*Fuzzer.java'); do 45 fuzzer_basename=$(basename -s .java $fuzzer) 46 javac -cp $BUILD_CLASSPATH $fuzzer 47 cp $SRC/$fuzzer_basename.class $OUT/ 48 49 # Create execution wrapper. 50 echo "#!/bin/sh 51# LLVMFuzzerTestOneInput for fuzzer detection. 52this_dir=\$(dirname \"\$0\") 53LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \ 54\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \ 55--cp=$RUNTIME_CLASSPATH \ 56--target_class=$fuzzer_basename \ 57--jvm_args=\"-Xmx2048m\" \ 58\$@" > $OUT/$fuzzer_basename 59 chmod u+x $OUT/$fuzzer_basename 60done 61