From 2d42c2b247145a53f798acbe15f91580d5a992e2 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Tue, 10 Feb 2009 14:28:57 +0000 Subject: [PATCH] Prevent code in test6.c from reading the 512 byte locking region (the PENDING_BYTE page) of a database file. Doing so triggers an assert failure in os_unix.c. (CVS 6276) FossilOrigin-Name: 2a6a43169220fab5a15a786e2a464b90cb893179 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/test6.c | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 03cd42727b..dc3b2caab7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Create\slinks\sfrom\sbackup\sAPI\sdocumentation\sto\sthe\sbackup\sapplication\snote.\nComment\schanges\sonly\s-\sno\schanges\sto\scode.\s(CVS\s6275) -D 2009-02-10T13:41:42 +C Prevent\scode\sin\stest6.c\sfrom\sreading\sthe\s512\sbyte\slocking\sregion\s(the\sPENDING_BYTE\spage)\sof\sa\sdatabase\sfile.\sDoing\sso\striggers\san\sassert\sfailure\sin\sos_unix.c.\s(CVS\s6276) +D 2009-02-10T14:28:57 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in c7a5a30fb6852bd7839b1024e1661da8549878ee F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -169,7 +169,7 @@ F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39 F src/test3.c 88a246b56b824275300e6c899634fbac1dc94b14 F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c F src/test5.c 162a1cea2105a2c460a3f39fa6919617b562a288 -F src/test6.c 10025acfb5d978abc08b3ddbba8b2ce4dd6ca0c1 +F src/test6.c 86d7918ccc2ff92ceb71cb59c6a078105f8885d2 F src/test7.c b94e68c2236de76889d82b8d7d8e00ad6a4d80b1 F src/test8.c 3637439424d0d21ff2dcf9b015c30fcc1e7bcb24 F src/test9.c 904ebe0ed1472d6bad17a81e2ecbfc20017dc237 @@ -701,7 +701,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P f6590dac4612d0d05105fa820e8fcb80b5907a40 -R d5f0d03566bc83fb0de348a58289fd37 -U drh -Z f36b4865f8619c82038b33c67badf672 +P 85de23fb4e63e5c71480c4c34efec331e774d7fb +R fc9b62f8eb9d21f86b7120b417d5c337 +U danielk1977 +Z 7d5d948a1e8d6b7ef2fab1a57b236f9f diff --git a/manifest.uuid b/manifest.uuid index a0ded13a0e..3a1fc0c83f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -85de23fb4e63e5c71480c4c34efec331e774d7fb \ No newline at end of file +2a6a43169220fab5a15a786e2a464b90cb893179 \ No newline at end of file diff --git a/src/test6.c b/src/test6.c index 6fc55b7ea6..cf6c2fcbde 100644 --- a/src/test6.c +++ b/src/test6.c @@ -14,7 +14,7 @@ ** the effect on the database file of an OS crash or power failure. This ** is used to test the ability of SQLite to recover from those situations. ** -** $Id: test6.c,v 1.41 2008/12/20 18:33:59 danielk1977 Exp $ +** $Id: test6.c,v 1.42 2009/02/10 14:28:57 danielk1977 Exp $ */ #if SQLITE_TEST /* This file is used for testing only */ #include "sqliteInt.h" @@ -564,8 +564,23 @@ static int cfOpen( pWrapper->nData = (4096 + pWrapper->iSize); pWrapper->zData = crash_malloc(pWrapper->nData); if( pWrapper->zData ){ + /* os_unix.c contains an assert() that fails if the caller attempts + ** to read data from the 512-byte locking region of a file opened + ** with the SQLITE_OPEN_MAIN_DB flag. This region of a database file + ** never contains valid data anyhow. So avoid doing such a read here. + */ + const int isDb = (flags&SQLITE_OPEN_MAIN_DB); + i64 iChunk = pWrapper->iSize; + if( iChunk>PENDING_BYTE && isDb ){ + iChunk = PENDING_BYTE; + } memset(pWrapper->zData, 0, pWrapper->nData); - rc = sqlite3OsRead(pReal, pWrapper->zData, pWrapper->iSize, 0); + rc = sqlite3OsRead(pReal, pWrapper->zData, iChunk, 0); + if( SQLITE_OK==rc && pWrapper->iSize>(PENDING_BYTE+512) && isDb ){ + i64 iOff = PENDING_BYTE+512; + iChunk = pWrapper->iSize - iOff; + rc = sqlite3OsRead(pReal, &pWrapper->zData[iOff], iChunk, iOff); + } }else{ rc = SQLITE_NOMEM; } -- 2.47.2