aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatena cyber <35799796+catenacyber@users.noreply.github.com>2021-03-31 18:19:59 +0200
committerGitHub <noreply@github.com>2021-03-31 09:19:59 -0700
commit0ce158f8f26285999904157d69b53f11b9f5fd13 (patch)
tree618f8c7bdea3d94d2e733b1bb7f90400cd717337
parenta87a6d546bed91c13e2513f50fe91c51ee74f7a7 (diff)
downloadoss-fuzz-0ce158f8f26285999904157d69b53f11b9f5fd13.tar.gz
Adds project fast-dds (#5487)
-rw-r--r--projects/fast-dds/Dockerfile26
-rwxr-xr-xprojects/fast-dds/build.sh53
-rw-r--r--projects/fast-dds/patch.diff74
-rw-r--r--projects/fast-dds/project.yaml9
4 files changed, 162 insertions, 0 deletions
diff --git a/projects/fast-dds/Dockerfile b/projects/fast-dds/Dockerfile
new file mode 100644
index 000000000..df5782e63
--- /dev/null
+++ b/projects/fast-dds/Dockerfile
@@ -0,0 +1,26 @@
+# Copyright 2021 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
+RUN apt-get update && apt install -y autoconf automake
+RUN git clone --depth 1 https://github.com/leethomason/tinyxml2
+RUN git clone --depth 1 https://github.com/chriskohlhoff/asio/
+RUN git clone --depth 1 https://github.com/eProsima/Fast-CDR.git
+RUN git clone --depth 1 https://github.com/eProsima/foonathan_memory_vendor.git
+RUN git clone --depth 1 https://github.com/eProsima/Fast-DDS.git
+COPY patch.diff $SRC
+COPY build.sh $SRC
+WORKDIR $SRC/Fast-DDS
diff --git a/projects/fast-dds/build.sh b/projects/fast-dds/build.sh
new file mode 100755
index 000000000..6831dffe3
--- /dev/null
+++ b/projects/fast-dds/build.sh
@@ -0,0 +1,53 @@
+#!/bin/bash -eu
+# Copyright 2021 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.
+#
+################################################################################
+
+
+(
+cd ../tinyxml2
+make -j$(nproc) all
+cp libtinyxml2.a /usr/local/lib/
+cp *.h /usr/local/include/
+)
+
+(
+cd ../asio/asio
+sh autogen.sh
+./configure
+make -j$(nproc) install
+)
+
+(
+cd ..
+mkdir Fast-CDR/build && cd Fast-CDR/build
+cmake .. -DBUILD_SHARED_LIBS=OFF
+cmake --build . --target install
+)
+
+(
+cd ..
+cd foonathan_memory_vendor
+mkdir build && cd build
+cmake .. -DBUILD_SHARED_LIBS=OFF
+cmake --build . --target install
+)
+
+# build project
+git apply ../patch.diff
+mkdir build && cd build
+cmake .. -DBUILD_SHARED_LIBS=OFF
+make -j $(nproc)
+cp src/cpp/fuzz* $OUT/
diff --git a/projects/fast-dds/patch.diff b/projects/fast-dds/patch.diff
new file mode 100644
index 000000000..e4f0ba2ed
--- /dev/null
+++ b/projects/fast-dds/patch.diff
@@ -0,0 +1,74 @@
+diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
+index b7fb777..615e955 100644
+--- a/src/cpp/CMakeLists.txt
++++ b/src/cpp/CMakeLists.txt
+@@ -484,6 +484,11 @@ elseif(NOT EPROSIMA_INSTALLER)
+ endif()
+ endif()
+
++if(DEFINED ENV{LIB_FUZZING_ENGINE})
++ add_executable(fuzz_processCDRMsg rtps/messages/fuzz_processCDRMsg.cpp)
++ target_link_libraries(fuzz_processCDRMsg ${PROJECT_NAME} $ENV{LIB_FUZZING_ENGINE})
++endif()
++
+ ###############################################################################
+ # Packaging
+ ###############################################################################
+diff --git a/src/cpp/rtps/messages/MessageReceiver.cpp b/src/cpp/rtps/messages/MessageReceiver.cpp
+index 962ca9b..0e82082 100644
+--- a/src/cpp/rtps/messages/MessageReceiver.cpp
++++ b/src/cpp/rtps/messages/MessageReceiver.cpp
+@@ -324,7 +324,11 @@ void MessageReceiver::processCDRMsg(
+
+ reset();
+
++#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
++ GuidPrefix_t participantGuidPrefix;
++#else
+ GuidPrefix_t participantGuidPrefix = participant_->getGuid().guidPrefix;
++#endif
+ dest_guid_prefix_ = participantGuidPrefix;
+
+ msg->pos = 0; //Start reading at 0
+@@ -513,7 +517,9 @@ void MessageReceiver::processCDRMsg(
+ submessage->pos = next_msg_pos;
+ }
+
++#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ participant_->assert_remote_participant_liveliness(source_guid_prefix_);
++#endif
+ }
+
+ bool MessageReceiver::checkRTPSHeader(
+diff --git a/src/cpp/rtps/messages/fuzz_processCDRMsg.cpp b/src/cpp/rtps/messages/fuzz_processCDRMsg.cpp
+new file mode 100644
+index 0000000..6a71817
+--- /dev/null
++++ b/src/cpp/rtps/messages/fuzz_processCDRMsg.cpp
+@@ -0,0 +1,26 @@
++#include <stdio.h>
++#include <stdlib.h>
++#include <stdint.h>
++#include <stdarg.h>
++#include <string.h>
++
++#include <fastrtps/rtps/messages/MessageReceiver.h>
++#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
++
++extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
++ const eprosima::fastrtps::rtps::Locator_t remoteLocator;
++ eprosima::fastrtps::rtps::MessageReceiver* rcv = new eprosima::fastrtps::rtps::MessageReceiver(NULL, 4096);
++
++ eprosima::fastrtps::rtps::CDRMessage_t msg(0);
++ msg.wraps = true;
++ msg.buffer = const_cast<eprosima::fastrtps::rtps::octet*>(data);
++ msg.length = size;
++ msg.max_size = size;
++ msg.reserved_size = size;
++
++ // TODO: Should we unlock in case UnregisterReceiver is called from callback ?
++ rcv->processCDRMsg(remoteLocator, &msg);
++ delete rcv;
++ return 0;
++}
++
diff --git a/projects/fast-dds/project.yaml b/projects/fast-dds/project.yaml
new file mode 100644
index 000000000..970e0b10d
--- /dev/null
+++ b/projects/fast-dds/project.yaml
@@ -0,0 +1,9 @@
+homepage: "https://www.eprosima.com/"
+language: c++
+primary_contact: "miguelcompany@eprosima.com"
+auto_ccs:
+- "p.antoine@catenacyber.fr"
+sanitizers:
+- address
+- undefined
+main_repo: 'https://github.com/eProsima/Fast-DDS.git'