1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Make sure the dbFileVers field in the Pager object is properly initialized

even if there is an I/O error while reading its content off of disk.

FossilOrigin-Name: 81ff698f62c8133818a3db1997ae7427705da23f
This commit is contained in:
drh
2010-03-05 20:17:45 +00:00
parent 5fea90762a
commit 29391c5b49
3 changed files with 37 additions and 10 deletions

View File

@@ -1,5 +1,8 @@
C Change\sa\scondition\sin\ssqlite3VdbeMemShallowCopy()\sto\savoid\saccessing\san\sunitialized\svariable\s(doing\sso\swas\snot\sdangerous,\sbut\scaused\sa\svalgrind\serror). -----BEGIN PGP SIGNED MESSAGE-----
D 2010-03-05T18:46:12 Hash: SHA1
C Make\ssure\sthe\sdbFileVers\sfield\sin\sthe\sPager\sobject\sis\sproperly\sinitialized\neven\sif\sthere\sis\san\sI/O\serror\swhile\sreading\sits\scontent\soff\sof\sdisk.
D 2010-03-05T20:17:46
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -152,7 +155,7 @@ F src/os_common.h 240c88b163b02c21a9f21f87d49678a0aa21ff30
F src/os_os2.c 75a8c7b9a00a2cf1a65f9fa4afbc27d46634bb2f F src/os_os2.c 75a8c7b9a00a2cf1a65f9fa4afbc27d46634bb2f
F src/os_unix.c 148d2f625db3727250c0b880481ae7630b6d0eb0 F src/os_unix.c 148d2f625db3727250c0b880481ae7630b6d0eb0
F src/os_win.c 1c7453c2df4dab26d90ff6f91272aea18bcf7053 F src/os_win.c 1c7453c2df4dab26d90ff6f91272aea18bcf7053
F src/pager.c ace73a84f53a551fb8b9334205af210a29874b2c F src/pager.c aafc314dee6e55be6cd6b4b1f9f8de62f0e1dfcc
F src/pager.h 1b32faf2e578ac3e7bcf9c9d11217128261c5c54 F src/pager.h 1b32faf2e578ac3e7bcf9c9d11217128261c5c54
F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
F src/pcache.c 4956b41d6ba913f7a8a56fbf32be78caed0e45c2 F src/pcache.c 4956b41d6ba913f7a8a56fbf32be78caed0e45c2
@@ -792,7 +795,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 6e3e014af91601ed1f3a9cbe23f7c4260a4d177f P 4793c381c6ff4e4d25433298be30028721a9cb67
R 388898322e7463920b97bb7843b3071a R 7b4a6ab87f116cc447789e269334119f
U dan U drh
Z 52df57cad18b098b73d39ae1b405ce26 Z 00a421bab571893d9c696160e4b5eaa4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFLkWbtoxKgR168RlERAl7RAJ4zorYQIvAsovJC+i4CWjSBy47hKwCfeUwU
RmW5deinND0RnxHbm1F9kGA=
=NuKq
-----END PGP SIGNATURE-----

View File

@@ -1 +1 @@
4793c381c6ff4e4d25433298be30028721a9cb67 81ff698f62c8133818a3db1997ae7427705da23f

View File

@@ -3339,6 +3339,7 @@ int sqlite3PagerOpen(
/* pPager->pBusyHandlerArg = 0; */ /* pPager->pBusyHandlerArg = 0; */
pPager->xReiniter = xReinit; pPager->xReiniter = xReinit;
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */ /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
*ppPager = pPager; *ppPager = pPager;
return SQLITE_OK; return SQLITE_OK;
} }
@@ -3488,9 +3489,25 @@ static int readDbPage(PgHdr *pPg){
rc = SQLITE_OK; rc = SQLITE_OK;
} }
if( pgno==1 ){ if( pgno==1 ){
if( rc ){
/* If the read is unsuccessful, set the dbFileVers[] to something
** that will never be a valid file version. dbFileVers[] is a copy
** of bytes 24..39 of the database. Bytes 28..31 should always be
** zero. Bytes 32..35 and 35..39 should be page numbers which are
** never 0xffffffff. So filling pPager->dbFileVers[] with all 0xff
** bytes should suffice.
**
** For an encrypted database, the situation is more complex: bytes
** 24..39 of the database are white noise. But the probability of
** white noising equaling 16 bytes of 0xff is vanishingly small so
** we should still be ok.
*/
memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
}else{
u8 *dbFileVers = &((u8*)pPg->pData)[24]; u8 *dbFileVers = &((u8*)pPg->pData)[24];
memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers)); memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
} }
}
CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM); CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM);
PAGER_INCR(sqlite3_pager_readdb_count); PAGER_INCR(sqlite3_pager_readdb_count);