1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Fix a problem in the memdb vfs xLock() function allowing clients to upgrade to EXCLUSIVE locks when other connections are holding SHARED.

FossilOrigin-Name: 15f0be8a640e7bfa4130edd4650a745337bd96083b119a1553f9abf9ff066806
This commit is contained in:
dan
2022-12-05 14:12:14 +00:00
parent 8c696375b5
commit 27ef91b551
3 changed files with 21 additions and 8 deletions

View File

@@ -371,9 +371,22 @@ static int memdbLock(sqlite3_file *pFile, int eLock){
if( eLock==pThis->eLock ) return SQLITE_OK;
memdbEnter(p);
if( eLock>SQLITE_LOCK_SHARED ){
assert( pThis->eLock>=SQLITE_LOCK_SHARED );
if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
rc = SQLITE_READONLY;
}else if( eLock==SQLITE_LOCK_EXCLUSIVE ){
/* Taking an EXCLUSIVE lock. Fail if we only have SHARED and any
** other client has any kind of write-lock. Also fail if any other
** client is holding read-lock. */
if( pThis->eLock<=SQLITE_LOCK_SHARED && p->nWrLock ){
rc = SQLITE_BUSY;
}else if( p->nRdLock>1 ){
rc = SQLITE_BUSY;
}
p->nWrLock = 1;
}else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
/* Upgrading to RESERVED or PENDING from SHARED. Fail if any other
** client has a write-lock of any kind. */
if( p->nWrLock ){
rc = SQLITE_BUSY;
}else{