From 5d3e7691a9bb7993ecec7c9f894574252aad8c2f Mon Sep 17 00:00:00 2001 From: "Patrice.S" Date: Thu, 20 Oct 2022 20:56:18 +0200 Subject: [PATCH] spring-cloud-stream: initial integration (#8778) --- projects/spring-cloud-stream/Dockerfile | 25 ++++ .../RabbitExchangeQueueProvisionerFuzzer.java | 138 ++++++++++++++++++ projects/spring-cloud-stream/build.sh | 69 +++++++++ projects/spring-cloud-stream/project.yaml | 18 +++ 4 files changed, 250 insertions(+) create mode 100644 projects/spring-cloud-stream/Dockerfile create mode 100644 projects/spring-cloud-stream/RabbitExchangeQueueProvisionerFuzzer.java create mode 100755 projects/spring-cloud-stream/build.sh create mode 100644 projects/spring-cloud-stream/project.yaml diff --git a/projects/spring-cloud-stream/Dockerfile b/projects/spring-cloud-stream/Dockerfile new file mode 100644 index 000000000..10a2ec60a --- /dev/null +++ b/projects/spring-cloud-stream/Dockerfile @@ -0,0 +1,25 @@ +# Copyright 2022 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 apt update && apt install -y openjdk-17-jdk + +RUN git clone --depth 1 https://github.com/spring-cloud/spring-cloud-stream + +COPY build.sh $SRC/ +COPY *Fuzzer.java $SRC/ +WORKDIR $SRC/spring-cloud-stream \ No newline at end of file diff --git a/projects/spring-cloud-stream/RabbitExchangeQueueProvisionerFuzzer.java b/projects/spring-cloud-stream/RabbitExchangeQueueProvisionerFuzzer.java new file mode 100644 index 000000000..498376dae --- /dev/null +++ b/projects/spring-cloud-stream/RabbitExchangeQueueProvisionerFuzzer.java @@ -0,0 +1,138 @@ +// Copyright 2022 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 com.rabbitmq.client.BlockedListener; +import com.rabbitmq.client.Channel; +import org.mockito.Mockito; +import org.springframework.amqp.AmqpException; +import org.springframework.amqp.rabbit.connection.Connection; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.connection.ConnectionListener; +import org.springframework.cloud.stream.binder.ExtendedProducerProperties; +import org.springframework.cloud.stream.binder.rabbit.properties.RabbitProducerProperties; +import org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner; + +public class RabbitExchangeQueueProvisionerFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + Channel channel = Mockito.mock(Channel.class); + Mockito.when(channel.getChannelNumber()).thenReturn(data.consumeInt()); + + Connection connection = Mockito.mock(DummyConnection.class); + Mockito.when(connection.createChannel(Mockito.anyBoolean())).thenReturn(channel); + Mockito.when(connection.isOpen()).thenReturn(true); + + DummyConnectionFactory connectionFactory = Mockito.mock(DummyConnectionFactory.class); + Mockito.when(connectionFactory.getPort()).thenReturn(data.consumeInt()); + Mockito.when(connectionFactory.getHost()).thenReturn(data.consumeString(50)); + Mockito.when(connectionFactory.getVirtualHost()).thenReturn(data.consumeString(50)); + Mockito.when(connectionFactory.getUsername()).thenReturn(data.consumeString(50)); + Mockito.when(connectionFactory.getPort()).thenReturn(data.consumeInt()); + Mockito.when(connectionFactory.createConnection()).thenReturn(connection); + + RabbitExchangeQueueProvisioner provisioner = new RabbitExchangeQueueProvisioner(connectionFactory); + if (data.consumeBoolean()) { + RabbitProducerProperties rabbitProducerProperties = new RabbitProducerProperties(); + rabbitProducerProperties.setCompress(data.consumeBoolean()); + rabbitProducerProperties.setHeaderPatterns(new String[]{data.consumeString(100)}); + rabbitProducerProperties.setBatchingEnabled(data.consumeBoolean()); + rabbitProducerProperties.setRoutingKey(data.consumeString(100)); + rabbitProducerProperties.setConfirmAckChannel(data.consumeString(100)); + rabbitProducerProperties.setUseConfirmHeader(data.consumeBoolean()); + rabbitProducerProperties.setStreamMessageConverterBeanName(data.consumeString(100)); + rabbitProducerProperties.setSuperStream(data.consumeBoolean()); + rabbitProducerProperties.setBatchingStrategyBeanName(data.consumeString(100)); + + ExtendedProducerProperties properties = new ExtendedProducerProperties(rabbitProducerProperties); + provisioner.provisionProducerDestination(data.consumeString(500), properties); + } + } + + public class DummyConnection implements Connection { + + @Override + public Channel createChannel(boolean b) throws AmqpException { + return null; + } + + @Override + public void close() throws AmqpException { + + } + + @Override + public boolean isOpen() { + return false; + } + + @Override + public int getLocalPort() { + return 0; + } + + @Override + public void addBlockedListener(BlockedListener blockedListener) { + + } + + @Override + public boolean removeBlockedListener(BlockedListener blockedListener) { + return false; + } + } + + public class DummyConnectionFactory implements ConnectionFactory { + + @Override + public Connection createConnection() throws AmqpException { + return null; + } + + @Override + public String getHost() { + return null; + } + + @Override + public int getPort() { + return 0; + } + + @Override + public String getVirtualHost() { + return null; + } + + @Override + public String getUsername() { + return null; + } + + @Override + public void addConnectionListener(ConnectionListener connectionListener) { + + } + + @Override + public boolean removeConnectionListener(ConnectionListener connectionListener) { + return false; + } + + @Override + public void clearConnectionListeners() { + + } + } +} diff --git a/projects/spring-cloud-stream/build.sh b/projects/spring-cloud-stream/build.sh new file mode 100755 index 000000000..2b900b99d --- /dev/null +++ b/projects/spring-cloud-stream/build.sh @@ -0,0 +1,69 @@ +#!/bin/bash -eu +# Copyright 2022 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. +# +################################################################################ + +export JAVA_HOME="$OUT/open-jdk-17" +mkdir -p $JAVA_HOME +rsync -aL --exclude=*.zip "/usr/lib/jvm/java-17-openjdk-amd64/" "$JAVA_HOME" + +# Remove all logging to console +touch empty-logback.xml +find . -name logback.xml -exec cp empty-logback.xml "{}" \; + +MAVEN_ARGS="-Djavac.src.version=17 -Djavac.target.version=17 -DskipTests -Dcheckstyle.skip=true" +CURRENT_VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \ + -Dexpression=project.version -q -DforceStdout | tail -n1) + +./mvnw package $MAVEN_ARGS +./mvnw package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade $MAVEN_ARGS -f binders/rabbit-binder/spring-cloud-stream-binder-rabbit/pom.xml +cp "binders/rabbit-binder/spring-cloud-stream-binder-rabbit/target/spring-cloud-stream-binder-rabbit-$CURRENT_VERSION.jar" "$OUT/spring-cloud-stream-binder-rabbit.jar" +cp "core/spring-cloud-stream/target/spring-cloud-stream-$CURRENT_VERSION.jar" "$OUT/spring-cloud-stream.jar" + +# Mockito dependencies +wget https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy/1.12.17/byte-buddy-1.12.17.jar -O "$OUT/byte-buddy.jar" +wget https://repo1.maven.org/maven2/org/objenesis/objenesis/3.3/objenesis-3.3.jar -O "$OUT/objenesis.jar" +wget https://repo1.maven.org/maven2/org/mockito/mockito-core/4.7.0/mockito-core-4.7.0.jar -O "$OUT/mockito.jar" +wget https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent/1.12.17/byte-buddy-agent-1.12.17.jar -O "$OUT/byte-buddy-agent.jar" + +ALL_JARS="spring-cloud-stream-binder-rabbit.jar spring-cloud-stream.jar mockito.jar byte-buddy.jar byte-buddy-agent.jar objenesis.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 + +# 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 + +for fuzzer in $(find $SRC -name '*Fuzzer.java'); do + fuzzer_basename=$(basename -s .java $fuzzer) + javac -cp $BUILD_CLASSPATH $fuzzer --release 17 + cp $SRC/*.class $OUT/ + + # Create an execution wrapper that executes Jazzer with the correct arguments. + echo "#!/bin/sh +# LLVMFuzzerTestOneInput for fuzzer detection. +this_dir=\$(dirname \"\$0\") +JAVA_HOME=\"\$this_dir/open-jdk-17/\" \ +JAVA_OPTS=\"-Dlogging.level.root=WARN -javaagent:\$this_dir/byte-buddy-agent.jar\" \ +LD_LIBRARY_PATH=\"\$this_dir/open-jdk-17/lib/server\":\$this_dir \ +\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \ +--instrumentation_includes=org.springframework.** \ +--cp=$RUNTIME_CLASSPATH \ +--target_class=$fuzzer_basename \ +--jvm_args=\"-Xmx2048m\" \ +\$@" > $OUT/$fuzzer_basename + chmod u+x $OUT/$fuzzer_basename +done \ No newline at end of file diff --git a/projects/spring-cloud-stream/project.yaml b/projects/spring-cloud-stream/project.yaml new file mode 100644 index 000000000..1ffb42b4f --- /dev/null +++ b/projects/spring-cloud-stream/project.yaml @@ -0,0 +1,18 @@ +homepage: "https://github.com/spring-projects/spring-data-mongodb" +language: jvm +main_repo: "https://github.com/spring-projects/spring-data-mongodb.git" +fuzzing_engines: + - libfuzzer +sanitizers: + - address +primary_contact: "pwebb@vmware.com" +auto_ccs: + - "wilkinsona@vmware.com" +vendor_ccs: + - "wagner@code-intelligence.com" + - "yakdan@code-intelligence.com" + - "glendowne@code-intelligence.com" + - "patrice.salathe@code-intelligence.com" + - "hlin@code-intelligence.com" + - "jacek.trossen@code-intelligence.com" + - "peter.samarin@code-intelligence.com" \ No newline at end of file