• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Build protoc with default options.
19unset CFLAGS CXXFLAGS
20mkdir $SRC/protobuf-install/
21cd $SRC/protobuf/
22./autogen.sh
23./configure --prefix=$SRC/protobuf-install
24make -j$(nproc)
25make install
26
27export PROTOC="$SRC/protobuf-install/bin/protoc"
28
29# Build protobuf-java (requires protoc in source tree).
30cd $SRC/protobuf/java/
31cp $PROTOC $SRC/protobuf/src/
32MAVEN_ARGS="-Dmaven.test.skip=true -Djavac.src.version=15 -Djavac.target.version=15"
33$MVN package $MAVEN_ARGS
34CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
35 -Dexpression=project.version -q -DforceStdout)
36cp "core/target/protobuf-java-$CURRENT_VERSION.jar" $OUT/protobuf-java.jar
37
38# Compile test protos with protoc.
39cd $SRC/
40$PROTOC --java_out=. --proto_path=. test-full.proto
41jar --create --file $OUT/test-full.jar foo/*
42
43ALL_JARS="protobuf-java.jar test-full.jar"
44
45# The classpath at build-time includes the project jars in $OUT as well as the
46# Jazzer API.
47BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH
48
49# All .jar and .class files lie in the same directory as the fuzzer at runtime.
50RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir
51
52for fuzzer in $(find $SRC -name '*Fuzzer.java'); do
53  fuzzer_basename=$(basename -s .java $fuzzer)
54  javac -cp $BUILD_CLASSPATH $fuzzer
55  cp $SRC/$fuzzer_basename.class $OUT/
56
57  # Create an execution wrapper that executes Jazzer with the correct arguments.
58  echo "#!/bin/sh
59# LLVMFuzzerTestOneInput for fuzzer detection.
60this_dir=\$(dirname \"\$0\")
61LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\" \
62\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \
63--cp=$RUNTIME_CLASSPATH \
64--target_class=$fuzzer_basename \
65--jvm_args=\"-Xmx2048m\" \
66\$@" > $OUT/$fuzzer_basename
67  chmod +x $OUT/$fuzzer_basename
68done
69
70