From: Eduard Bagdasaryan Date: Tue, 17 Dec 2019 15:01:05 +0000 (+0000) Subject: Fix shared memory size calculation on 64-bit systems (#520) X-Git-Tag: SQUID_5_0_1~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b454559b3cdb682904c393ab33b25da1c0f23e0a;p=thirdparty%2Fsquid.git Fix shared memory size calculation on 64-bit systems (#520) Since commit 2253ee0, the wrong type (uint32 instead of size_t) was used to calculate the PagePool::theLevels size. theLevels memory (positioned by different and correct code) did not overlap with the raw pages buffer, but the raw pages buffer could, in some cases, be 32 bits short, placing the last 4 bytes of the last page outside of allocated memory. In practice, shared memory allocations are page-aligned, and the difference in 4 bytes was probably compensated by the extra allocated bytes in most (or perhaps even all) cases. --- diff --git a/src/ipc/mem/PageStack.cc b/src/ipc/mem/PageStack.cc index ccf28d5717..0cd604403e 100644 --- a/src/ipc/mem/PageStack.cc +++ b/src/ipc/mem/PageStack.cc @@ -122,7 +122,7 @@ Ipc::Mem::PageStack::sharedMemorySize() const size_t Ipc::Mem::PageStack::SharedMemorySize(const uint32_t, const unsigned int capacity, const size_t pageSize) { - const size_t levelsSize = PageId::maxPurpose * sizeof(std::atomic); + const auto levelsSize = PageId::maxPurpose * sizeof(Levels_t); const size_t pagesDataSize = capacity * pageSize; return StackSize(capacity) + LevelsPaddingSize(capacity) + levelsSize + pagesDataSize; }