]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix shared memory size calculation on 64-bit systems (#520)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Tue, 17 Dec 2019 15:01:05 +0000 (15:01 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 20 Dec 2019 05:39:10 +0000 (05:39 +0000)
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.

src/ipc/mem/PageStack.cc

index ccf28d5717be524d1de9cc3c0c40655577052f85..0cd604403e3fb119e2a472161f028d04a53580fe 100644 (file)
@@ -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<Ipc::Mem::PageStack::Value>);
+    const auto levelsSize = PageId::maxPurpose * sizeof(Levels_t);
     const size_t pagesDataSize = capacity * pageSize;
     return StackSize(capacity) + LevelsPaddingSize(capacity) + levelsSize + pagesDataSize;
 }