From 8d0fbb79f32bb94c2214a0cd8abb303442157dd1 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Fri, 25 Aug 2023 07:50:18 -0700 Subject: [PATCH 1/2] Fix invalid downcast in ~xml_oarchive_impl The destructor of the xml_oarchive_impl winds up calling `this->windup()` which in turn invokes `this->This()->...` which essentially static_cast's to a Archive, which by this point in time is long-since destructed. By simply inlining the implementation of windup(), we avoid the UB and minimize the required code changes --- include/boost/archive/detail/interface_oarchive.hpp | 7 ------- include/boost/archive/impl/xml_oarchive_impl.ipp | 5 +++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/include/boost/archive/detail/interface_oarchive.hpp b/include/boost/archive/detail/interface_oarchive.hpp index 8f7aa6d79f..88e857bc27 100644 --- a/include/boost/archive/detail/interface_oarchive.hpp +++ b/include/boost/archive/detail/interface_oarchive.hpp @@ -44,13 +44,6 @@ class interface_oarchive typedef mpl::bool_ is_saving; // return a pointer to the most derived class - #if BOOST_WORKAROUND(BOOST_GCC_VERSION,>=40900)||\ - BOOST_WORKAROUND(BOOST_CLANG,>=1)&&\ - (__clang_major__>3 || __clang_major__==3 && __clang_minor__ >= 8) - /* https://github.com/boostorg/poly_collection/issues/15 */ - - __attribute__((no_sanitize("undefined"))) - #endif Archive * This(){ return static_cast(this); } diff --git a/include/boost/archive/impl/xml_oarchive_impl.ipp b/include/boost/archive/impl/xml_oarchive_impl.ipp index 0f4ccbbf98..9f74c61d04 100644 --- a/include/boost/archive/impl/xml_oarchive_impl.ipp +++ b/include/boost/archive/impl/xml_oarchive_impl.ipp @@ -131,8 +131,9 @@ BOOST_ARCHIVE_DECL xml_oarchive_impl::~xml_oarchive_impl(){ if(boost::core::uncaught_exceptions() > 0) return; - if(0 == (this->get_flags() & no_header)) - this->windup(); + if(0 == (this->get_flags() & no_header)){ + this->put("\n"); + } } } // namespace archive From 6388138a0c448be5190d6832fe4437fe5b781857 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Fri, 25 Aug 2023 07:53:07 -0700 Subject: [PATCH 2/2] Fix invalid vptr access in extended_type_info_no_rtti constructor Initializing a base class in the initializer list with a member function in the derived is invalid in gcc as the object isn't fully-formed We instead just inline the body of `get_key()` which avoids the issue. --- .../boost/serialization/extended_type_info_no_rtti.hpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/include/boost/serialization/extended_type_info_no_rtti.hpp b/include/boost/serialization/extended_type_info_no_rtti.hpp index ca3fae025b..68df0eef52 100644 --- a/include/boost/serialization/extended_type_info_no_rtti.hpp +++ b/include/boost/serialization/extended_type_info_no_rtti.hpp @@ -100,13 +100,9 @@ class extended_type_info_no_rtti : } }; public: - #if BOOST_WORKAROUND(BOOST_GCC_VERSION,>=40900)||\ - BOOST_WORKAROUND(BOOST_CLANG,>=1)&&\ - (__clang_major__>3 || __clang_major__==3 && __clang_minor__ >= 8) - __attribute__((no_sanitize("undefined"))) - #endif extended_type_info_no_rtti() : - no_rtti_system::extended_type_info_no_rtti_0(get_key()) + no_rtti_system::extended_type_info_no_rtti_0( + action::value >::invoke()) { key_register(); }