Skip to content

Commit 4981fc2

Browse files
Alexandre CostaMsftBrettShirley
authored andcommitted
Range lock code incorrectly grows array of ranges
[Substrate:75b6c001fffebcfa7f5445a5bc841eaadf357e94]
1 parent ec4fb65 commit 4981fc2

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

dev/ese/src/ese/fmp.cxx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,24 +1956,22 @@ ERR FMP::ErrIAddRangeLock( const PGNO pgnoStart, const PGNO pgnoEnd )
19561956
// get the pointers to the pointers to the current and new range locks so
19571957
// that we can manipulate them easily
19581958

1959-
RANGELOCK** pprangelockCur = &m_rgprangelock[ m_msRangeLock.GroupActive() ];
1960-
RANGELOCK** pprangelockNew = &m_rgprangelock[ m_msRangeLock.GroupInactive() ];
1959+
RANGELOCK** pprangelockCur = &m_rgprangelock[ m_msRangeLock.GroupActive() ];
1960+
RANGELOCK** pprangelockNew = &m_rgprangelock[ m_msRangeLock.GroupInactive() ];
1961+
const SIZE_T crangeNew = (*pprangelockCur)->crange + 1;
19611962

19621963
// the new range lock doesn't have enough room to store all the ranges we need
19631964

1964-
if ( (*pprangelockNew)->crangeMax < (*pprangelockCur)->crange + 1 )
1965+
if ( (*pprangelockNew)->crangeMax < crangeNew )
19651966
{
19661967
// double the size of the new range lock
19671968

1968-
SIZE_T crangeMax = 2 * (*pprangelockNew)->crangeMax;
1969-
SIZE_T cbrangelock = sizeof( RANGELOCK ) + crangeMax * sizeof( RANGE );
1969+
const LONG crangeMaxT = LNextPowerOf2( (LONG)crangeNew );
1970+
const SIZE_T crangeMax = ( ( crangeMaxT >= 0 ) && ( (SIZE_T)crangeMaxT >= crangeNew ) ) ? (SIZE_T)crangeMaxT : crangeNew;
1971+
const SIZE_T cbrangelock = sizeof( RANGELOCK ) + crangeMax * sizeof( RANGE );
19701972

1971-
RANGELOCK * const prangelock = (RANGELOCK*)PvOSMemoryHeapAlloc( cbrangelock + 0x80);
1972-
1973-
if ( !prangelock )
1974-
{
1975-
Error( ErrERRCheck( JET_errOutOfMemory ) );
1976-
}
1973+
RANGELOCK * const prangelock = (RANGELOCK*)PvOSMemoryHeapAlloc( cbrangelock );
1974+
Alloc( prangelock )
19771975

19781976
prangelock->crangeMax = crangeMax;
19791977

@@ -1982,6 +1980,8 @@ ERR FMP::ErrIAddRangeLock( const PGNO pgnoStart, const PGNO pgnoEnd )
19821980
*pprangelockNew = prangelock;
19831981
}
19841982

1983+
Assert( (*pprangelockNew)->crangeMax >= crangeNew );
1984+
19851985
// copy the state of the current range lock to the new range lock
19861986

19871987
SIZE_T irange;
@@ -1998,7 +1998,7 @@ ERR FMP::ErrIAddRangeLock( const PGNO pgnoStart, const PGNO pgnoEnd )
19981998

19991999
// set the number of ranges in the new range lock
20002000

2001-
(*pprangelockNew)->crange = (*pprangelockCur)->crange + 1;
2001+
(*pprangelockNew)->crange = crangeNew;
20022002

20032003
// cause new writers to see the new range lock and wait until all writers
20042004
// that saw the old range lock are done writing
@@ -2056,6 +2056,7 @@ VOID FMP::IRemoveRangeLock( const PGNO pgnoStart, const PGNO pgnoEnd )
20562056

20572057
// set the number of ranges in the new range lock
20582058

2059+
Assert( (*pprangelockNew)->crangeMax >= irangeDest );
20592060
(*pprangelockNew)->crange = irangeDest;
20602061

20612062
// cause new writers to see the new range lock and wait until all writers

0 commit comments

Comments
 (0)