Check transport type of msg and corresponding region

This commit is contained in:
Alexey Rybalchenko 2021-04-09 12:27:16 +02:00
parent 950a54c08b
commit 2db2516141
2 changed files with 11 additions and 1 deletions

View File

@ -109,12 +109,17 @@ class Message final : public fair::mq::Message
, fRegionPtr(nullptr)
, fLocalPtr(static_cast<char*>(data))
{
if (region->GetType() != GetType()) {
LOG(error) << "region type (" << region->GetType() << ") does not match message type (" << GetType() << ")";
throw TransportError(tools::ToString("region type (", region->GetType(), ") does not match message type (", GetType(), ")"));
}
if (reinterpret_cast<const char*>(data) >= reinterpret_cast<const char*>(region->GetData()) &&
reinterpret_cast<const char*>(data) <= reinterpret_cast<const char*>(region->GetData()) + region->GetSize()) {
fMeta.fHandle = (boost::interprocess::managed_shared_memory::handle_t)(reinterpret_cast<const char*>(data) - reinterpret_cast<const char*>(region->GetData()));
} else {
LOG(error) << "trying to create region message with data from outside the region";
throw std::runtime_error("trying to create region message with data from outside the region");
throw TransportError("trying to create region message with data from outside the region");
}
fManager.IncrementMsgCounter();
}

View File

@ -109,6 +109,11 @@ class Message final : public fair::mq::Message
, fAlignment(0)
, fMsg(std::make_unique<zmq_msg_t>())
{
if (region->GetType() != GetType()) {
LOG(error) << "region type (" << region->GetType() << ") does not match message type (" << GetType() << ")";
throw TransportError(tools::ToString("region type (", region->GetType(), ") does not match message type (", GetType(), ")"));
}
// FIXME: make this zero-copy:
// simply taking over the provided buffer can casue premature delete, since region could be
// destroyed before the message is sent out. Needs lifetime extension for the ZMQ region.