1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-09-11 08:30:57 +03:00

Avoid crashing when using an RBU VFS with a version 1 parent VFS.

FossilOrigin-Name: d149772d18c47bf986decb7e08d148b1d417bbcc8522fd6240ead836ec34074b
This commit is contained in:
dan
2023-01-12 19:11:41 +00:00
parent 64f03fa54f
commit 67da9239ba
4 changed files with 114 additions and 9 deletions

View File

@@ -4588,9 +4588,12 @@ static int rbuVfsClose(sqlite3_file *pFile){
sqlite3_free(p->zDel);
if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
sqlite3_io_methods *pMeth = p->pReal->pMethods;
rbuMainlistRemove(p);
rbuUnlockShm(p);
p->pReal->pMethods->xShmUnmap(p->pReal, 0);
if( pMeth->iVersion>1 && pMeth->xShmUnmap ){
pMeth->xShmUnmap(p->pReal, 0);
}
}
else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
rbuUpdateTempSize(p, 0);
@@ -5049,6 +5052,25 @@ static int rbuVfsOpen(
rbuVfsShmUnmap, /* xShmUnmap */
0, 0 /* xFetch, xUnfetch */
};
static sqlite3_io_methods rbuvfs_io_methods1 = {
1, /* iVersion */
rbuVfsClose, /* xClose */
rbuVfsRead, /* xRead */
rbuVfsWrite, /* xWrite */
rbuVfsTruncate, /* xTruncate */
rbuVfsSync, /* xSync */
rbuVfsFileSize, /* xFileSize */
rbuVfsLock, /* xLock */
rbuVfsUnlock, /* xUnlock */
rbuVfsCheckReservedLock, /* xCheckReservedLock */
rbuVfsFileControl, /* xFileControl */
rbuVfsSectorSize, /* xSectorSize */
rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
0, 0, 0, 0, 0, 0
};
rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
rbu_file *pFd = (rbu_file *)pFile;
@@ -5103,10 +5125,15 @@ static int rbuVfsOpen(
rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
}
if( pFd->pReal->pMethods ){
sqlite3_io_methods *pMeth = pFd->pReal->pMethods;
/* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
** pointer and, if the file is a main database file, link it into the
** mutex protected linked list of all such files. */
pFile->pMethods = &rbuvfs_io_methods;
if( pMeth->iVersion<2 || pMeth->xShmLock==0 ){
pFile->pMethods = &rbuvfs_io_methods1;
}else{
pFile->pMethods = &rbuvfs_io_methods;
}
if( flags & SQLITE_OPEN_MAIN_DB ){
rbuMainlistAdd(pFd);
}