Validation in deserializer (#36)

* Validation in Deserializer

Added validation in CDR deserialization: max buffer length is checked
when deserializing fields and strings are checked for null-terminator
(except for wstrings, which are serialized without null-terminator).

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Catch exceptions in serdata functions

In serdata functions rmw_print, rmw_to_sample and rmw_from_sample
catch exceptions so that correct return code is given when functions
are called from ddsi.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Improve deserialisation validation

Refactored the deserialisation validation functions so that sequence
length is checked more properly and protection against overflows.
Renamed source files for exceptions so that it conforms to ros2 /
google c++ style guide.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
This commit is contained in:
dennis-adlink 2019-09-19 11:56:26 +02:00 committed by eboasson
parent b39efafd62
commit 0e6fd30a8c
11 changed files with 379 additions and 160 deletions

View file

@ -0,0 +1,41 @@
// Copyright 2018 to 2019 ADLINK Technology
//
// 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.
#include "rmw_cyclonedds_cpp/deserialization_exception.hpp"
using rmw_cyclonedds_cpp::DeserializationException;
DeserializationException::DeserializationException(const char * const & message)
: Exception(message)
{
}
DeserializationException::DeserializationException(const DeserializationException & ex)
: Exception(ex)
{
}
DeserializationException & DeserializationException::operator=(const DeserializationException & ex)
{
if (this != &ex) {
Exception::operator=(ex);
}
return *this;
}
DeserializationException::~DeserializationException() throw()
{
}
const char * const DeserializationException::DEFAULT_MESSAGE = "Invalid data";