From: drh <> Date: Tue, 22 Mar 2022 19:41:55 +0000 (+0000) Subject: Harden the xShmLock method of both the unix and Windows VFSes so that they X-Git-Tag: version-3.39.0~289 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56d88aad299a57368408a69c7357963a9ddd8f89;p=thirdparty%2Fsqlite.git 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 --- diff --git a/manifest b/manifest index 8de26e80b2..e8a0b85d78 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\ssqlite3_serialize()\sand\ssqlite3_deserialize()\sinterfaces\saccessible\nto\sloadable\sextensions. -D 2022-03-22T11:22:55.530 +C Harden\sthe\sxShmLock\smethod\sof\sboth\sthe\sunix\sand\sWindows\sVFSes\sso\sthat\sthey\nare\srobust\sagainst\sbeing\sinvoked\swhen\sthe\sSHM\sfile\sis\snot\sopen. +D 2022-03-22T19:41:55.891 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -536,8 +536,8 @@ F src/os.c b1c4f2d485961e9a5b6b648c36687d25047c252222e9660b7cc25a6e1ea436ab F src/os.h 26890f540b475598cd9881dcc68931377b8d429d3ea3e2eeb64470cde64199f8 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 -F src/os_unix.c f0dc85d439ece53120c4071c98876758ec24e6f713b67af3711af033c897091e -F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9 +F src/os_unix.c 1f71ec8c87621f75c9c5ea973f5e8ce2f1d23fe760c01ed2814fe4b98b639825 +F src/os_win.c a8ea80037e81127ca01959daa87387cc135f325c88dc745376c4f760de852a10 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 42120492784fc9bcd9082b5c9b5e329b7318c357f9f3574a1bbfcf7418910356 F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3 @@ -1945,9 +1945,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c7a2047e93df36c172be0be773f9a04150dafe7ba1773269d74016418d262fc4 da874180d35aacdeb9c06f5b425e8909d833e2765179c4337854d56b8a624fd5 -R bf3c838ea5a83946446e0f353de9bf76 -T +closed da874180d35aacdeb9c06f5b425e8909d833e2765179c4337854d56b8a624fd5 +P 81f8746bc65828fb91e170393f22f1f4e9c587a8938e8c11b72315fcd6131403 +R d298ad7f59290d0a6efedfc24438d25c U drh -Z 464016fe3bfc08f8aed0a703c852c5bf +Z 4cb272d1327d5bb30f85a15fc2446351 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 56691d0ab3..4c5bd46b09 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -81f8746bc65828fb91e170393f22f1f4e9c587a8938e8c11b72315fcd6131403 \ No newline at end of file +67d8b434f628d44c4a90ce8ff5ab2e381f500bb42bdbfab9a17d21925a2ec6cd \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index f4e5421469..03ac3e46c9 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 ); diff --git a/src/os_win.c b/src/os_win.c index d7c436eff9..8832c8012a 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -4070,10 +4070,14 @@ static int winShmLock( winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */ winShm *p = pDbFd->pShm; /* The shared memory being locked */ winShm *pX; /* For looping over all siblings */ - winShmNode *pShmNode = p->pShmNode; + winShmNode *pShmNode; int rc = SQLITE_OK; /* Result code */ u16 mask; /* Mask of locks to take or release */ + if( p==0 ) return SQLITE_IOERR_SHMLOCK; + pShmNode = p->pShmNode; + if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK; + assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); assert( n>=1 ); assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)