Skip to content

Commit 0f94098

Browse files
Fix #6994 - limits lockfile to 2GB for B3_0 (#7021)
* Fix: limits lockfile to 2GB for B3_0 * Remove redundant status vector copying, add parentheses to multiline IF
1 parent d545ffc commit 0f94098

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/lock/lock.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ const SLONG HASH_MIN_SLOTS = 101;
143143
const SLONG HASH_MAX_SLOTS = 65521;
144144
const USHORT HISTORY_BLOCKS = 256;
145145

146+
const ULONG MAX_TABLE_LENGTH = SLONG_MAX;
147+
146148
// SRQ_ABS_PTR uses this macro.
147149
#define SRQ_BASE ((UCHAR*) m_sharedMemory->getHeader())
148150

@@ -1252,14 +1254,14 @@ bool LockManager::Extent::initialize(bool)
12521254
void LockManager::Extent::mutexBug(int, const char*)
12531255
{ }
12541256

1255-
bool LockManager::createExtent(CheckStatusWrapper* statusVector)
1257+
bool LockManager::createExtent(CheckStatusWrapper* statusVector, ULONG memorySize)
12561258
{
12571259
Firebird::PathName name;
12581260
get_shared_file_name(name, (ULONG) m_extents.getCount());
12591261

12601262
Extent& extent = m_extents.add();
12611263

1262-
if (!extent.mapFile(statusVector, name.c_str(), m_memorySize))
1264+
if (!extent.mapFile(statusVector, name.c_str(), memorySize ? memorySize : m_memorySize))
12631265
{
12641266
m_extents.pop();
12651267
logError("LockManager::createExtent() mapFile", local_status);
@@ -1292,25 +1294,41 @@ UCHAR* LockManager::alloc(USHORT size, CheckStatusWrapper* statusVector)
12921294
size = FB_ALIGN(size, FB_ALIGNMENT);
12931295
ASSERT_ACQUIRED;
12941296
ULONG block = m_sharedMemory->getHeader()->lhb_used;
1297+
ULONG memorySize = m_memorySize;
12951298

12961299
// Make sure we haven't overflowed the lock table. If so, bump the size of the table.
12971300

12981301
if (m_sharedMemory->getHeader()->lhb_used + size > m_sharedMemory->getHeader()->lhb_length)
12991302
{
1303+
// New table size shouldn't exceed max table length
1304+
if (m_sharedMemory->getHeader()->lhb_length + memorySize > MAX_TABLE_LENGTH)
1305+
{
1306+
if (m_sharedMemory->getHeader()->lhb_used + size <= MAX_TABLE_LENGTH)
1307+
memorySize = MAX_TABLE_LENGTH - m_sharedMemory->getHeader()->lhb_length;
1308+
else
1309+
{
1310+
// Return an error if can't alloc enough memory
1311+
(Arg::Gds(isc_lockmanerr) <<
1312+
Arg::Gds(isc_random) << Arg::Str("lock table size exceeds limit") <<
1313+
Arg::StatusVector(statusVector)).copyTo(statusVector);
1314+
1315+
return NULL;
1316+
}
1317+
}
13001318
#ifdef USE_SHMEM_EXT
13011319
// round up so next object starts at beginning of next extent
13021320
block = m_sharedMemory->getHeader()->lhb_used = m_sharedMemory->getHeader()->lhb_length;
1303-
if (createExtent(*statusVector))
1321+
if (createExtent(*statusVector, memorySize))
13041322
{
1305-
m_sharedMemory->getHeader()->lhb_length += m_memorySize;
1323+
m_sharedMemory->getHeader()->lhb_length += memorySize;
13061324
}
13071325
else
13081326
#elif (defined HAVE_OBJECT_MAP)
13091327
Firebird::WriteLockGuard guard(m_remapSync, FB_FUNCTION);
13101328
// Post remapping notifications
13111329
remap_local_owners();
13121330
// Remap the shared memory region
1313-
const ULONG new_length = m_sharedMemory->sh_mem_length_mapped + m_memorySize;
1331+
const ULONG new_length = m_sharedMemory->sh_mem_length_mapped + memorySize;
13141332
if (m_sharedMemory->remapFile(statusVector, new_length, true))
13151333
{
13161334
ASSERT_ACQUIRED;

src/lock/lock_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ class LockManager : private Firebird::RefCounted,
564564

565565
SRQ_PTR REL_PTR(const void* item);
566566
void* ABS_PTR(SRQ_PTR item);
567-
bool createExtent();
567+
bool createExtent(ULONG memorySize = 0);
568568
#endif
569569
};
570570

0 commit comments

Comments
 (0)