]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix incorrect size calculation in PMR resource (PR 94906)
authorJonathan Wakely <jwakely@redhat.com>
Tue, 12 May 2020 08:54:44 +0000 (09:54 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 12 May 2020 17:49:17 +0000 (18:49 +0100)
Calculating the size of a chunk being returned to the upstream allocator
was done with a 32-bit type, so it wrapped if the chunk was 4GB or
larger.

I don't know how to test this without allocating 4GB, so there's no test
in the testsuite. It has been tested manually of course.

Backport from mainline
2020-05-04  Jonathan Wakely  <jwakely@redhat.com>

PR libstdc++/94906
* src/c++17/memory_resource.cc
(monotonic_buffer_resource::_Chunk::release): Use size_t for shift
operands.

libstdc++-v3/ChangeLog
libstdc++-v3/src/c++17/memory_resource.cc

index a1d06b6fff171507facc731bfe5f53f0bba7321c..57dde8c5533ce14de55a77436b4983cfbd342d68 100644 (file)
@@ -1,3 +1,13 @@
+2020-05-12  Jonathan Wakely  <jwakely@redhat.com>
+
+       Backport from mainline
+       2020-05-04  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/94906
+       * src/c++17/memory_resource.cc
+       (monotonic_buffer_resource::_Chunk::release): Use size_t for shift
+       operands.
+
 2020-05-07  Eric Botcazou  <ebotcazou@adacore.com>
 
        * config/abi/post/sparc64-linux-gnu/baseline_symbols.txt: Update.
index e28526d1bfed420150b0df4137b245e208207759..f39360cb4bf465de4ac9bdb9a9dc76e16f85704e 100644 (file)
@@ -228,8 +228,8 @@ namespace pmr
          if (__ch->_M_canary != (__ch->_M_size | __ch->_M_align))
            return; // buffer overflow detected!
 
-         size_t __size = (1u << __ch->_M_size);
-         size_t __align = (1u << __ch->_M_align);
+         size_t __size = (size_t)1 << __ch->_M_size;
+         size_t __align = (size_t)1 << __ch->_M_align;
          void* __start = (char*)(__ch + 1) - __size;
          __r->deallocate(__start, __size, __align);
        }