Adds project fast-dds (#5487)

This commit is contained in:
Catena cyber 2021-03-31 18:19:59 +02:00 committed by GitHub
parent a87a6d546b
commit 0ce158f8f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 162 additions and 0 deletions

View File

@ -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

53
projects/fast-dds/build.sh Executable file
View File

@ -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/

View File

@ -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;
+}
+

View File

@ -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'