/ Check-in [d73e93cf]
Login

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

Overview
Comment:Make sure filenames passed into sqlite3OsOpen() always have the extra zero-terminators needed by sqlite3_uri_parameter().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d73e93cfdc9441ade77b796dcdcf6eeb753cb398
User & Date: drh 2012-01-03 14:50:45
Context
2012-01-04
12:57
Fix typos and comments and make minor changes to a few function names, as suggested by readership. check-in: e9d05cbb user: drh tags: trunk
2012-01-03
21:54
Pull all the latest trunk changes over into the apple-osx branch. check-in: 8a048423 user: drh tags: apple-osx
21:33
Experimental changes to prevent buffer overreads when parsing a corrupt database file. Closed-Leaf check-in: 9e5add51 user: drh tags: no-overread
14:50
Make sure filenames passed into sqlite3OsOpen() always have the extra zero-terminators needed by sqlite3_uri_parameter(). check-in: d73e93cf user: drh tags: trunk
2012-01-02
18:20
Remove the code that attempts to find the sector size from the OS and hardcode the xSectorSize methods of the unix and windows VFSes to return SQLITE_DEFAULT_SECTOR_SIZE, which is now set to 4096 unless overridden. check-in: 03d8362c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  3862   3862       */
  3863   3863       if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){
  3864   3864         rc = SQLITE_IOERR_FSTAT;
  3865   3865         goto shm_open_err;
  3866   3866       }
  3867   3867   
  3868   3868   #ifdef SQLITE_SHM_DIRECTORY
  3869         -    nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 30;
         3869  +    nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
  3870   3870   #else
  3871         -    nShmFilename = 5 + (int)strlen(pDbFd->zPath);
         3871  +    nShmFilename = 6 + (int)strlen(pDbFd->zPath);
  3872   3872   #endif
  3873   3873       pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
  3874   3874       if( pShmNode==0 ){
  3875   3875         rc = SQLITE_NOMEM;
  3876   3876         goto shm_open_err;
  3877   3877       }
  3878   3878       memset(pShmNode, 0, sizeof(*pShmNode));

Changes to src/os_win.c.

  2462   2462     /* Allocate space for the new sqlite3_shm object.  Also speculatively
  2463   2463     ** allocate space for a new winShmNode and filename.
  2464   2464     */
  2465   2465     p = sqlite3_malloc( sizeof(*p) );
  2466   2466     if( p==0 ) return SQLITE_IOERR_NOMEM;
  2467   2467     memset(p, 0, sizeof(*p));
  2468   2468     nName = sqlite3Strlen30(pDbFd->zPath);
  2469         -  pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 15 );
         2469  +  pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 16 );
  2470   2470     if( pNew==0 ){
  2471   2471       sqlite3_free(p);
  2472   2472       return SQLITE_IOERR_NOMEM;
  2473   2473     }
  2474   2474     memset(pNew, 0, sizeof(*pNew));
  2475   2475     pNew->zFilename = (char*)&pNew[1];
  2476   2476     sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);

Changes to src/pager.c.

  4403   4403     */
  4404   4404     pPtr = (u8 *)sqlite3MallocZero(
  4405   4405       ROUND8(sizeof(*pPager)) +      /* Pager structure */
  4406   4406       ROUND8(pcacheSize) +           /* PCache object */
  4407   4407       ROUND8(pVfs->szOsFile) +       /* The main db file */
  4408   4408       journalFileSize * 2 +          /* The two journal files */ 
  4409   4409       nPathname + 1 + nUri +         /* zFilename */
  4410         -    nPathname + 8 + 1              /* zJournal */
         4410  +    nPathname + 8 + 2              /* zJournal */
  4411   4411   #ifndef SQLITE_OMIT_WAL
  4412         -    + nPathname + 4 + 1              /* zWal */
         4412  +    + nPathname + 4 + 2            /* zWal */
  4413   4413   #endif
  4414   4414     );
  4415   4415     assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
  4416   4416     if( !pPtr ){
  4417   4417       sqlite3_free(zPathname);
  4418   4418       return SQLITE_NOMEM;
  4419   4419     }
................................................................................
  4428   4428     /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
  4429   4429     if( zPathname ){
  4430   4430       assert( nPathname>0 );
  4431   4431       pPager->zJournal =   (char*)(pPtr += nPathname + 1 + nUri);
  4432   4432       memcpy(pPager->zFilename, zPathname, nPathname);
  4433   4433       memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
  4434   4434       memcpy(pPager->zJournal, zPathname, nPathname);
  4435         -    memcpy(&pPager->zJournal[nPathname], "-journal", 8);
         4435  +    memcpy(&pPager->zJournal[nPathname], "-journal\000", 8+1);
  4436   4436       sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
  4437   4437   #ifndef SQLITE_OMIT_WAL
  4438   4438       pPager->zWal = &pPager->zJournal[nPathname+8+1];
  4439   4439       memcpy(pPager->zWal, zPathname, nPathname);
  4440         -    memcpy(&pPager->zWal[nPathname], "-wal", 4);
         4440  +    memcpy(&pPager->zWal[nPathname], "-wal\000", 4+1);
  4441   4441       sqlite3FileSuffix3(pPager->zFilename, pPager->zWal);
  4442   4442   #endif
  4443   4443       sqlite3_free(zPathname);
  4444   4444     }
  4445   4445     pPager->pVfs = pVfs;
  4446   4446     pPager->vfsFlags = vfsFlags;
  4447   4447   

Changes to src/util.c.

  1160   1160   ** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
  1161   1161   ** three characters, then shorten the suffix on z[] to be the last three
  1162   1162   ** characters of the original suffix.
  1163   1163   **
  1164   1164   ** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
  1165   1165   ** do the suffix shortening regardless of URI parameter.
  1166   1166   **
         1167  +** Assume that zBaseFilename contains two \000 terminator bytes (so that
         1168  +** it can be harmlessly passed into sqlite3_uri_parameter()) and copy both
         1169  +** zero terminator bytes into the end of the revised name.
         1170  +**
  1167   1171   ** Examples:
  1168   1172   **
  1169   1173   **     test.db-journal    =>   test.nal
  1170   1174   **     test.db-wal        =>   test.wal
  1171   1175   **     test.db-shm        =>   test.shm
  1172   1176   **     test.db-mj7f3319fa =>   test.9fa
  1173   1177   */
  1174   1178   void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
         1179  +  assert( zBaseFilename[strlen(zBaseFilename)+1]==0 );
  1175   1180   #if SQLITE_ENABLE_8_3_NAMES<2
  1176   1181     if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) )
  1177   1182   #endif
  1178   1183     {
  1179   1184       int i, sz;
  1180   1185       sz = sqlite3Strlen30(z);
  1181   1186       for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
  1182         -    if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4);
         1187  +    if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 5);
  1183   1188     }
  1184   1189   }
  1185   1190   #endif

Changes to src/vdbeaux.c.

  1835   1835       i64 offset = 0;
  1836   1836       int res;
  1837   1837       int retryCount = 0;
  1838   1838       int nMainFile;
  1839   1839   
  1840   1840       /* Select a master journal file name */
  1841   1841       nMainFile = sqlite3Strlen30(zMainFile);
  1842         -    zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XX", zMainFile);
         1842  +    zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile);
  1843   1843       if( zMaster==0 ) return SQLITE_NOMEM;
  1844   1844       do {
  1845   1845         u32 iRandom;
  1846   1846         if( retryCount ){
  1847   1847           if( retryCount>100 ){
  1848   1848             sqlite3_log(SQLITE_FULL, "MJ delete: %s", zMaster);
  1849   1849             sqlite3OsDelete(pVfs, zMaster, 0);