/ Check-in [2a6a4316]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2a6a43169220fab5a15a786e2a464b90cb893179
User & Date: danielk1977 2009-02-10 14:28:57
Context
2009-02-10
14:45
Reduce the number of iterations in one of the savepoint4.test crash tests. (CVS 6277) check-in: fafb07b8 user: danielk1977 tags: trunk
14:28
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) check-in: 2a6a4316 user: danielk1977 tags: trunk
13:41
Create links from backup API documentation to the backup application note. Comment changes only - no changes to code. (CVS 6275) check-in: 85de23fb user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test6.c.

    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains code that modified the OS layer in order to simulate
    14     14   ** the effect on the database file of an OS crash or power failure.  This
    15     15   ** is used to test the ability of SQLite to recover from those situations.
    16     16   **
    17         -** $Id: test6.c,v 1.41 2008/12/20 18:33:59 danielk1977 Exp $
           17  +** $Id: test6.c,v 1.42 2009/02/10 14:28:57 danielk1977 Exp $
    18     18   */
    19     19   #if SQLITE_TEST          /* This file is used for testing only */
    20     20   #include "sqliteInt.h"
    21     21   #include "tcl.h"
    22     22   
    23     23   #ifndef SQLITE_OMIT_DISKIO  /* This file is a no-op if disk I/O is disabled */
    24     24   
................................................................................
   560    560       rc = sqlite3OsFileSize(pReal, &iSize);
   561    561       pWrapper->iSize = (int)iSize;
   562    562     }
   563    563     if( rc==SQLITE_OK ){
   564    564       pWrapper->nData = (4096 + pWrapper->iSize);
   565    565       pWrapper->zData = crash_malloc(pWrapper->nData);
   566    566       if( pWrapper->zData ){
          567  +      /* os_unix.c contains an assert() that fails if the caller attempts
          568  +      ** to read data from the 512-byte locking region of a file opened
          569  +      ** with the SQLITE_OPEN_MAIN_DB flag. This region of a database file
          570  +      ** never contains valid data anyhow. So avoid doing such a read here.
          571  +      */
          572  +      const int isDb = (flags&SQLITE_OPEN_MAIN_DB);
          573  +      i64 iChunk = pWrapper->iSize;
          574  +      if( iChunk>PENDING_BYTE && isDb ){
          575  +        iChunk = PENDING_BYTE;
          576  +      }
   567    577         memset(pWrapper->zData, 0, pWrapper->nData);
   568         -      rc = sqlite3OsRead(pReal, pWrapper->zData, pWrapper->iSize, 0); 
          578  +      rc = sqlite3OsRead(pReal, pWrapper->zData, iChunk, 0); 
          579  +      if( SQLITE_OK==rc && pWrapper->iSize>(PENDING_BYTE+512) && isDb ){
          580  +        i64 iOff = PENDING_BYTE+512;
          581  +        iChunk = pWrapper->iSize - iOff;
          582  +        rc = sqlite3OsRead(pReal, &pWrapper->zData[iOff], iChunk, iOff);
          583  +      }
   569    584       }else{
   570    585         rc = SQLITE_NOMEM;
   571    586       }
   572    587     }
   573    588     if( rc!=SQLITE_OK && pWrapper->pMethod ){
   574    589       sqlite3OsClose(pFile);
   575    590     }