SQLite

Check-in [15f0be8a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem in the memdb vfs xLock() function allowing clients to upgrade to EXCLUSIVE locks when other connections are holding SHARED. Forum post 5adb92e2baca3678.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 15f0be8a640e7bfa4130edd4650a745337bd96083b119a1553f9abf9ff066806
User & Date: dan 2022-12-05 14:12:14
Original Comment: Fix a problem in the memdb vfs xLock() function allowing clients to upgrade to EXCLUSIVE locks when other connections are holding SHARED.
References
2022-12-07
16:58
Streamline and improve testing of the locking in the memdb VFS. Follow-on to [15f0be8a640e7bfa]. (check-in: d71a0837 user: drh tags: trunk)
Context
2022-12-05
14:23
Fix a problem in the memdb vfs xLock() function allowing clients to upgrade to EXCLUSIVE locks when other connections are holding SHARED. (check-in: d18cce37 user: drh tags: branch-3.40)
14:20
Add test case that should have been part of previous commit. (check-in: dc7dd2d3 user: dan tags: trunk)
14:12
Fix a problem in the memdb vfs xLock() function allowing clients to upgrade to EXCLUSIVE locks when other connections are holding SHARED. Forum post 5adb92e2baca3678. (check-in: 15f0be8a user: dan tags: trunk)
13:07
Remove SQLITE_EXPERIMENTAL tag from sqlite3_vtab_collation() and fix a related doc typo. (check-in: 35d670b3 user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/memdb.c.

367
368
369
370
371
372
373

374
375










376


377
378
379
380
381
382
383
static int memdbLock(sqlite3_file *pFile, int eLock){
  MemFile *pThis = (MemFile*)pFile;
  MemStore *p = pThis->pStore;
  int rc = SQLITE_OK;
  if( eLock==pThis->eLock ) return SQLITE_OK;
  memdbEnter(p);
  if( eLock>SQLITE_LOCK_SHARED ){

    if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
      rc = SQLITE_READONLY;










    }else if( pThis->eLock<=SQLITE_LOCK_SHARED ){


      if( p->nWrLock ){
        rc = SQLITE_BUSY;
      }else{
        p->nWrLock = 1;
      }
    }
  }else if( eLock==SQLITE_LOCK_SHARED ){







>


>
>
>
>
>
>
>
>
>
>

>
>







367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
static int memdbLock(sqlite3_file *pFile, int eLock){
  MemFile *pThis = (MemFile*)pFile;
  MemStore *p = pThis->pStore;
  int rc = SQLITE_OK;
  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{
        p->nWrLock = 1;
      }
    }
  }else if( eLock==SQLITE_LOCK_SHARED ){