|
| 1 | +#!/bin/bash -eu |
| 2 | +# Copyright 2025 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 | +ALL_JARS="" |
| 19 | + |
| 20 | +pushd "${SRC}/caffeine" |
| 21 | + ./gradlew --no-daemon caffeine:jar |
| 22 | + install -v ./caffeine/build/libs/caffeine-*-SNAPSHOT.jar "$OUT/caffeine.jar" |
| 23 | + ALL_JARS="${ALL_JARS} caffeine.jar" |
| 24 | +popd |
| 25 | + |
| 26 | +# The classpath at build-time includes the project jars in $OUT as well as the |
| 27 | +# Jazzer API. |
| 28 | +BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH |
| 29 | + |
| 30 | +# All .jar and .class files lie in the same directory as the fuzzer at runtime. |
| 31 | +RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir |
| 32 | + |
| 33 | +# compile all java files and copy them to $OUT |
| 34 | +javac -cp $SRC:$BUILD_CLASSPATH -g $SRC/*.java |
| 35 | +cp $SRC/*.class $OUT/ |
| 36 | + |
| 37 | +for fuzzer in $(find $SRC -name '*Fuzzer.java'); do |
| 38 | + fuzzer_basename=$(basename -s .java $fuzzer) |
| 39 | + |
| 40 | + # Create an execution wrapper that executes Jazzer with the correct arguments. |
| 41 | + echo "#!/bin/bash |
| 42 | +# LLVMFuzzerTestOneInput for fuzzer detection. |
| 43 | +this_dir=\$(dirname \"\$0\") |
| 44 | +if [[ \"\$@\" =~ (^| )-runs=[0-9]+($| ) ]]; then |
| 45 | + mem_settings='-Xmx1900m:-Xss900k' |
| 46 | +else |
| 47 | + mem_settings='-Xmx2048m:-Xss1024k' |
| 48 | +fi |
| 49 | +LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \ |
| 50 | +\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \ |
| 51 | +--cp=$RUNTIME_CLASSPATH \ |
| 52 | +--target_class=$fuzzer_basename \ |
| 53 | +--jvm_args=\"\$mem_settings\" \ |
| 54 | +\$@" > $OUT/$fuzzer_basename |
| 55 | + chmod u+x $OUT/$fuzzer_basename |
| 56 | +done |
0 commit comments