@@ -143,6 +143,8 @@ const SLONG HASH_MIN_SLOTS = 101;
143
143
const SLONG HASH_MAX_SLOTS = 65521 ;
144
144
const USHORT HISTORY_BLOCKS = 256 ;
145
145
146
+ const ULONG MAX_TABLE_LENGTH = SLONG_MAX;
147
+
146
148
// SRQ_ABS_PTR uses this macro.
147
149
#define SRQ_BASE ((UCHAR*) m_sharedMemory->getHeader ())
148
150
@@ -1252,14 +1254,14 @@ bool LockManager::Extent::initialize(bool)
1252
1254
void LockManager::Extent::mutexBug (int , const char *)
1253
1255
{ }
1254
1256
1255
- bool LockManager::createExtent (CheckStatusWrapper* statusVector)
1257
+ bool LockManager::createExtent (CheckStatusWrapper* statusVector, ULONG memorySize )
1256
1258
{
1257
1259
Firebird::PathName name;
1258
1260
get_shared_file_name (name, (ULONG) m_extents.getCount ());
1259
1261
1260
1262
Extent& extent = m_extents.add ();
1261
1263
1262
- if (!extent.mapFile (statusVector, name.c_str (), m_memorySize))
1264
+ if (!extent.mapFile (statusVector, name.c_str (), memorySize ? memorySize : m_memorySize))
1263
1265
{
1264
1266
m_extents.pop ();
1265
1267
logError (" LockManager::createExtent() mapFile" , local_status);
@@ -1292,25 +1294,41 @@ UCHAR* LockManager::alloc(USHORT size, CheckStatusWrapper* statusVector)
1292
1294
size = FB_ALIGN (size, FB_ALIGNMENT);
1293
1295
ASSERT_ACQUIRED;
1294
1296
ULONG block = m_sharedMemory->getHeader ()->lhb_used ;
1297
+ ULONG memorySize = m_memorySize;
1295
1298
1296
1299
// Make sure we haven't overflowed the lock table. If so, bump the size of the table.
1297
1300
1298
1301
if (m_sharedMemory->getHeader ()->lhb_used + size > m_sharedMemory->getHeader ()->lhb_length )
1299
1302
{
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
+ }
1300
1318
#ifdef USE_SHMEM_EXT
1301
1319
// round up so next object starts at beginning of next extent
1302
1320
block = m_sharedMemory->getHeader ()->lhb_used = m_sharedMemory->getHeader ()->lhb_length ;
1303
- if (createExtent (*statusVector))
1321
+ if (createExtent (*statusVector, memorySize ))
1304
1322
{
1305
- m_sharedMemory->getHeader ()->lhb_length += m_memorySize ;
1323
+ m_sharedMemory->getHeader ()->lhb_length += memorySize ;
1306
1324
}
1307
1325
else
1308
1326
#elif (defined HAVE_OBJECT_MAP)
1309
1327
Firebird::WriteLockGuard guard (m_remapSync, FB_FUNCTION);
1310
1328
// Post remapping notifications
1311
1329
remap_local_owners ();
1312
1330
// 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 ;
1314
1332
if (m_sharedMemory->remapFile (statusVector, new_length, true ))
1315
1333
{
1316
1334
ASSERT_ACQUIRED;
0 commit comments