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:
parent
b39efafd62
commit
0e6fd30a8c
11 changed files with 379 additions and 160 deletions
38
rmw_cyclonedds_cpp/src/rmw_node.cpp
Normal file → Executable file
38
rmw_cyclonedds_cpp/src/rmw_node.cpp
Normal file → Executable file
|
@ -713,31 +713,37 @@ extern "C" rmw_ret_t rmw_deserialize(
|
|||
const rosidl_message_type_support_t * type_support,
|
||||
void * ros_message)
|
||||
{
|
||||
cycdeser sd(serialized_message->buffer, serialized_message->buffer_length);
|
||||
bool ok;
|
||||
const rosidl_message_type_support_t * ts;
|
||||
if ((ts =
|
||||
get_message_typesupport_handle(type_support,
|
||||
rosidl_typesupport_introspection_c__identifier)) != nullptr)
|
||||
{
|
||||
auto members =
|
||||
static_cast<const rosidl_typesupport_introspection_c__MessageMembers *>(ts->data);
|
||||
MessageTypeSupport_c msgts(members);
|
||||
ok = msgts.deserializeROSmessage(sd, ros_message, nullptr);
|
||||
} else {
|
||||
try {
|
||||
cycdeser sd(serialized_message->buffer, serialized_message->buffer_length);
|
||||
const rosidl_message_type_support_t * ts;
|
||||
if ((ts =
|
||||
get_message_typesupport_handle(type_support,
|
||||
rosidl_typesupport_introspection_cpp::typesupport_identifier)) != nullptr)
|
||||
rosidl_typesupport_introspection_c__identifier)) != nullptr)
|
||||
{
|
||||
auto members =
|
||||
static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(ts->data);
|
||||
MessageTypeSupport_cpp msgts(members);
|
||||
static_cast<const rosidl_typesupport_introspection_c__MessageMembers *>(ts->data);
|
||||
MessageTypeSupport_c msgts(members);
|
||||
ok = msgts.deserializeROSmessage(sd, ros_message, nullptr);
|
||||
} else {
|
||||
RMW_SET_ERROR_MSG("rmw_serialize: type support trouble");
|
||||
return RMW_RET_ERROR;
|
||||
if ((ts =
|
||||
get_message_typesupport_handle(type_support,
|
||||
rosidl_typesupport_introspection_cpp::typesupport_identifier)) != nullptr)
|
||||
{
|
||||
auto members =
|
||||
static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(ts->data);
|
||||
MessageTypeSupport_cpp msgts(members);
|
||||
ok = msgts.deserializeROSmessage(sd, ros_message, nullptr);
|
||||
} else {
|
||||
RMW_SET_ERROR_MSG("rmw_serialize: type support trouble");
|
||||
return RMW_RET_ERROR;
|
||||
}
|
||||
}
|
||||
} catch (rmw_cyclonedds_cpp::Exception & e) {
|
||||
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("rmw_serialize: %s", e.what());
|
||||
ok = false;
|
||||
}
|
||||
|
||||
return ok ? RMW_RET_OK : RMW_RET_ERROR;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue