From b281e9557bd1a8578dae141430869924760a45ee Mon Sep 17 00:00:00 2001 From: Sebastian Theophil Date: Tue, 28 Jun 2016 10:30:59 +0200 Subject: [PATCH] Fix undefined behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit managed_open_or_create_impl::priv_open_or_create calls construct_func.get_min_size() before construct_func::operator(). The implementation of create_open_func::get_min_size called the static function segment_manager::get_min_size() by making a member function call on m_frontend->get_segment_manager() which is still null at this point. The crashes when compiling with clang’s undefined behavior sanitizer --- include/boost/interprocess/detail/managed_memory_impl.hpp | 4 ++-- include/boost/interprocess/detail/managed_multi_shared_memory.hpp | 4 ++-- include/boost/interprocess/detail/managed_open_or_create_impl.hpp | 0 include/boost/interprocess/mapped_region.hpp | 2 +- include/boost/interprocess/sync/shm/named_creation_functor.hpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) mode change 100644 => 100755 include/boost/interprocess/detail/managed_memory_impl.hpp mode change 100644 => 100755 include/boost/interprocess/detail/managed_multi_shared_memory.hpp mode change 100644 => 100755 include/boost/interprocess/detail/managed_open_or_create_impl.hpp diff --git a/include/boost/interprocess/detail/managed_memory_impl.hpp b/include/boost/interprocess/detail/managed_memory_impl.hpp old mode 100644 new mode 100755 index 0a82230c..939dc6a9 --- a/include/boost/interprocess/detail/managed_memory_impl.hpp +++ b/include/boost/interprocess/detail/managed_memory_impl.hpp @@ -747,9 +747,9 @@ class create_open_func } } - std::size_t get_min_size() const + static std::size_t get_min_size() { - const size_type sz = m_frontend->get_segment_manager()->get_min_size(); + const size_type sz = BasicManagedMemoryImpl::segment_manager::get_min_size(); if(sz > std::size_t(-1)){ //The minimum size is not representable by std::size_t BOOST_ASSERT(false); diff --git a/include/boost/interprocess/detail/managed_multi_shared_memory.hpp b/include/boost/interprocess/detail/managed_multi_shared_memory.hpp old mode 100644 new mode 100755 index 3d0ba669..68799b02 --- a/include/boost/interprocess/detail/managed_multi_shared_memory.hpp +++ b/include/boost/interprocess/detail/managed_multi_shared_memory.hpp @@ -219,9 +219,9 @@ class basic_managed_multi_shared_memory return false; } - std::size_t get_min_size() const + static std::size_t get_min_size() { - const size_type sz = mp_frontend->get_segment_manager()->get_min_size(); + const size_type sz = self_t::segment_manager::get_min_size(); if(sz > std::size_t(-1)){ //The minimum size is not representable by std::size_t BOOST_ASSERT(false); diff --git a/include/boost/interprocess/detail/managed_open_or_create_impl.hpp b/include/boost/interprocess/detail/managed_open_or_create_impl.hpp old mode 100644 new mode 100755 diff --git a/include/boost/interprocess/mapped_region.hpp b/include/boost/interprocess/mapped_region.hpp index e5eee0bf..4037a919 100644 --- a/include/boost/interprocess/mapped_region.hpp +++ b/include/boost/interprocess/mapped_region.hpp @@ -876,7 +876,7 @@ struct null_mapped_region_function bool operator()(void *, std::size_t , bool) const { return true; } - std::size_t get_min_size() const + static std::size_t get_min_size() { return 0; } }; diff --git a/include/boost/interprocess/sync/shm/named_creation_functor.hpp b/include/boost/interprocess/sync/shm/named_creation_functor.hpp index b4cc7786..137a1a8e 100644 --- a/include/boost/interprocess/sync/shm/named_creation_functor.hpp +++ b/include/boost/interprocess/sync/shm/named_creation_functor.hpp @@ -66,7 +66,7 @@ class named_creation_functor } } - std::size_t get_min_size() const + static std::size_t get_min_size() { return sizeof(T); } private: