aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordrh <>2022-03-22 19:41:55 +0000
committerdrh <>2022-03-22 19:41:55 +0000
commit56d88aad299a57368408a69c7357963a9ddd8f89 (patch)
tree8ea80e4008df1329fe8a2421025d1429c570e35e /src/os_unix.c
parent6fad5776c09afe77e1db5804c514eaeb0f8b0d7d (diff)
downloadsqlite-56d88aad299a57368408a69c7357963a9ddd8f89.tar.gz
sqlite-56d88aad299a57368408a69c7357963a9ddd8f89.zip
Harden the xShmLock method of both the unix and Windows VFSes so that they
are robust against being invoked when the SHM file is not open. FossilOrigin-Name: 67d8b434f628d44c4a90ce8ff5ab2e381f500bb42bdbfab9a17d21925a2ec6cd
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index f4e542146..03ac3e46c 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4910,11 +4910,17 @@ static int unixShmLock(
int flags /* What to do with the lock */
){
unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
- unixShm *p = pDbFd->pShm; /* The shared memory being locked */
- unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
+ unixShm *p; /* The shared memory being locked */
+ unixShmNode *pShmNode; /* The underlying file iNode */
int rc = SQLITE_OK; /* Result code */
u16 mask; /* Mask of locks to take or release */
- int *aLock = pShmNode->aLock;
+ int *aLock;
+
+ p = pDbFd->pShm;
+ if( p==0 ) return SQLITE_IOERR_SHMLOCK;
+ pShmNode = p->pShmNode;
+ if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
+ aLock = pShmNode->aLock;
assert( pShmNode==pDbFd->pInode->pShmNode );
assert( pShmNode->pInode==pDbFd->pInode );