From 88bc1f7a06a55bde9288579a3f59ebd6bfc4546d Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Tue, 30 Jun 2020 14:44:29 +0200 Subject: [PATCH] Shm: throw if requested message size exceeds total segment size --- fairmq/shmem/Message.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fairmq/shmem/Message.h b/fairmq/shmem/Message.h index 4c78f2ac..12991cbc 100644 --- a/fairmq/shmem/Message.h +++ b/fairmq/shmem/Message.h @@ -251,6 +251,10 @@ class Message final : public fair::mq::Message // boost::interprocess::managed_shared_memory::size_type actualSize = size; // char* hint = 0; // unused for boost::interprocess::allocate_new // fLocalPtr = fManager.Segment().allocation_command(boost::interprocess::allocate_new, size, actualSize, hint); + size_t segmentSize = fManager.Segment().get_size(); + if (size > segmentSize) { + throw MessageBadAlloc(tools::ToString("Requested message size (", size, ") exceeds segment size (", segmentSize, ")")); + } if (alignment == 0) { fLocalPtr = reinterpret_cast(fManager.Segment().allocate(size)); } else {