From 90de9533ecef08e98d82e8f8c26fad57839e4184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sun, 12 Jul 2020 11:07:50 +0200 Subject: [PATCH] Fixes #151 ("Buffer overflow in monotonic_buffer_resource::do_allocate"). --- doc/container.qbk | 1 + src/monotonic_buffer_resource.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/doc/container.qbk b/doc/container.qbk index b1f38a2..fab8d94 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1329,6 +1329,7 @@ use [*Boost.Container]? There are several reasons for that: * [@https://github.com/boostorg/container/issues/145 GitHub #145: ['"Allocations not handled correctly in some cases of vector move with unequal allocators"]]. * [@https://github.com/boostorg/container/pull/146 GitHub #146: ['"Changes for Embarcadero C++ clang-based compilers, targeting Boost 1.74. Addition needed for Embarcardero clang-based compilers"]]. * [@https://github.com/boostorg/container/pull/148 GitHub #148: ['"Fix static initialization issues in pmr global resources"]]. + * [@https://github.com/boostorg/container/issues/151 GitHub #151: ['"Buffer overflow in monotonic_buffer_resource::do_allocate"]]. [endsect] diff --git a/src/monotonic_buffer_resource.cpp b/src/monotonic_buffer_resource.cpp index 29ffde1..c676992 100644 --- a/src/monotonic_buffer_resource.cpp +++ b/src/monotonic_buffer_resource.cpp @@ -141,6 +141,9 @@ void* monotonic_buffer_resource::do_allocate(std::size_t bytes, std::size_t alig //See if there is room in current buffer std::size_t aligner = 0u; if(this->remaining_storage(alignment, aligner) < bytes){ + //The new buffer will be aligned to the strictest alignment so reset + //the aligner, which was needed for the old buffer. + aligner = 0u; //Update next_buffer_size to at least bytes this->increase_next_buffer_at_least_to(bytes); //Now allocate and update internal data