From d4a1313fd02a18fac4a202916a77f3b56d07b259 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Fri, 6 Oct 2023 01:02:21 +0100 Subject: [PATCH] jooq: initial integration (#11075) Initial integration of project jooq. Signed-off-by: Arthur Chan --- projects/jooq/Dockerfile | 33 ++++++++++ projects/jooq/GenerationToolFuzzer.java | 34 ++++++++++ projects/jooq/build.sh | 87 +++++++++++++++++++++++++ projects/jooq/project.yaml | 11 ++++ 4 files changed, 165 insertions(+) create mode 100644 projects/jooq/Dockerfile create mode 100644 projects/jooq/GenerationToolFuzzer.java create mode 100644 projects/jooq/build.sh create mode 100644 projects/jooq/project.yaml diff --git a/projects/jooq/Dockerfile b/projects/jooq/Dockerfile new file mode 100644 index 000000000..51ae4b289 --- /dev/null +++ b/projects/jooq/Dockerfile @@ -0,0 +1,33 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +########################################################################## +FROM gcr.io/oss-fuzz-base/base-builder-jvm + +RUN curl -L https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip -o maven.zip && \ + unzip maven.zip -d $SRC/maven && \ + rm -rf maven.zip + +RUN curl -L https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_linux-x64_bin.tar.gz -o jdk.tar.gz && \ + tar zxf jdk.tar.gz && \ + rm -rf jdk.tar.gz + +RUN curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip -o protoc.zip && mkdir -p $SRC/protoc && unzip protoc.zip -d $SRC/protoc && rm -rf protoc.zip + +ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn +ENV JAVA_HOME="$SRC/jdk-17" +ENV PATH="$JAVA_HOME/bin:$SRC/protoc/bin:$PATH" +RUN git clone --depth 1 https://github.com/jOOQ/jOOQ.git jOOQ.git +COPY *.sh *.java $SRC/ +WORKDIR $SRC/jOOQ.git diff --git a/projects/jooq/GenerationToolFuzzer.java b/projects/jooq/GenerationToolFuzzer.java new file mode 100644 index 000000000..21d875322 --- /dev/null +++ b/projects/jooq/GenerationToolFuzzer.java @@ -0,0 +1,34 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.jooq.codegen.GeneratorException; +import org.jooq.codegen.GenerationTool; +import org.jooq.exception.ConfigurationException; + +// Generated with https://github.com/ossf/fuzz-introspector/tree/main/tools/auto-fuzz +// Minor modifications to beautify code and ensure exception is caught. +// jvm-autofuzz-heuristics-1 +// Heuristic name: jvm-autofuzz-heuristics-1 +// Target method: [org.jooq.codegen.GenerationTool] public static void generate(java.lang.String) throws java.lang.Exception +public class GenerationToolFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws Exception { + try { + GenerationTool.generate(data.consumeRemainingAsString()); + } catch (ConfigurationException | GeneratorException e) { + // Known exception + } + } +} diff --git a/projects/jooq/build.sh b/projects/jooq/build.sh new file mode 100644 index 000000000..39a3b8abf --- /dev/null +++ b/projects/jooq/build.sh @@ -0,0 +1,87 @@ +#!/bin/bash -eu +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +########################################################################## +chmod +x $SRC/protoc/bin/protoc + +$MVN clean package -Dmaven.javadoc.skip=true -DskipTests=true -Dpmd.skip=true \ + -Dencoding=UTF-8 -Dmaven.antrun.skip=true -Dcheckstyle.skip=true \ + -DperformRelease=True -pl jOOQ -pl jOOQ-meta -pl jOOQ-codegen \ + dependency:copy-dependencies +CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \ + -Dexpression=project.version -q -DforceStdout) + +cp "./jOOQ/target/jooq-$CURRENT_VERSION.jar" $OUT/jooq.jar +cp "./jOOQ-meta/target/jooq-meta-$CURRENT_VERSION.jar" $OUT/jooq-meta.jar +cp "./jOOQ-codegen/target/jooq-codegen-$CURRENT_VERSION.jar" $OUT/jooq-codegen.jar + +JARFILE_LIST= +for JARFILE in $(find ./*/target/dependency -name *.jar) +do + cp $JARFILE $OUT/ + JARFILE_LIST="$JARFILE_LIST$(basename $JARFILE) " +done + +curr_dir=$(pwd) +rm -rf $OUT/jar_temp +mkdir $OUT/jar_temp +cd $OUT/jar_temp +for JARFILE in $JARFILE_LIST +do + jar -xf $OUT/$JARFILE +done + +cd $curr_dir + +ALL_JARS='jooq.jar jooq-meta.jar jooq-codegen.jar' + +# The classpath at build-time includes the project jars in $OUT as well as the +# Jazzer API. +BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH:$OUT/jar_temp + +# All .jar and .class files lie in the same directory as the fuzzer at runtime. +RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir:\$this_dir/jar_temp + +cp -r $JAVA_HOME $OUT/ + +for fuzzer in $(find $SRC -name '*Fuzzer.java') +do + fuzzer_basename=$(basename -s .java $fuzzer) + $JAVA_HOME/bin/javac -cp $BUILD_CLASSPATH $fuzzer + cp $SRC/$fuzzer_basename*.class $OUT/ + + # Create an execution wrapper that executes Jazzer with the correct arguments. + echo "#!/bin/bash + # LLVMFuzzerTestOneInput for fuzzer detection. + this_dir=\$(dirname "\$0") + if [[ "\$@" =~ (^| )-runs=[0-9]+($| ) ]] + then + mem_settings='-Xmx1900m:-Xss900k' + else + mem_settings='-Xmx2048m:-Xss1024k' + fi + export JAVA_HOME=\$this_dir/$(basename $JAVA_HOME) + export LD_LIBRARY_PATH="\$JAVA_HOME/lib/server":\$this_dir + export PATH=\$JAVA_HOME/bin:\$PATH + + \$this_dir/jazzer_driver \ + --agent_path=\$this_dir/jazzer_agent_deploy.jar \ + --cp=$RUNTIME_CLASSPATH \ + --target_class=$fuzzer_basename \ + --jvm_args="\$mem_settings" \ + \$@" > $OUT/$fuzzer_basename + + chmod u+x $OUT/$fuzzer_basename +done diff --git a/projects/jooq/project.yaml b/projects/jooq/project.yaml new file mode 100644 index 000000000..837f220dd --- /dev/null +++ b/projects/jooq/project.yaml @@ -0,0 +1,11 @@ +homepage: https://github.com/jOOQ/jOOQ.git +main_repo: https://github.com/jOOQ/jOOQ.git +language: jvm +fuzzing_engines: +- libfuzzer +sanitizers: +- address +vendor_ccs: +- david@adalogics.com +- adam@adalogics.com +- arthur.chan@adalogics.com