SQLite

Check-in [d18cce37]
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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | branch-3.40
Files: files | file ages | folders
SHA3-256: d18cce37b5b73bb2a4f28eb1b55eb2c3ffe1fc23c921c13170af3d74a549f48e
User & Date: drh 2022-12-05 14:23:06
Context
2022-12-26
15:21
Fix an infinite loop in the MEMSYS5 auxiliary memory allocator that occurs for memory allocations between 500MiB and 1GiB in size. Error introduced by check-in [949133231f8f751a]. The problem only affects builds that include the SQLITE_ENABLE_MEMSYS5 compile-time option. (check-in: c10d40ca user: drh tags: branch-3.40)
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
Regenerate the configure script so that it includes the correct patch number. (check-in: e2ae2ea1 user: drh tags: branch-3.40)
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)
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 ){