/ Check-in [3013f9a6]
Login

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

Overview
Comment:Fix the sqlite3_quota_file() function in test_quota.c so that it adds the second nul-terminator to all file names that will be passed to a VFS xOpen method.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3013f9a67cc6097c14e40a6155c1401f51f4da78
User & Date: dan 2012-01-11 11:20:42
Context
2012-01-11
15:47
Make the pager less vulnerable to problems caused by shifting sector sizes when rolling back a hot journal. check-in: 629108c8 user: drh tags: trunk
11:20
Fix the sqlite3_quota_file() function in test_quota.c so that it adds the second nul-terminator to all file names that will be passed to a VFS xOpen method. check-in: 3013f9a6 user: dan tags: trunk
01:01
Prevent winOpenSharedMemory from masking the real return code from its call to winOpen. Also, add asserts to check the double-zero termination of database file names. check-in: 93a65776 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_quota.c.

   933    933   */
   934    934   int sqlite3_quota_file(const char *zFilename){
   935    935     char *zFull;
   936    936     sqlite3_file *fd;
   937    937     int rc;
   938    938     int outFlags = 0;
   939    939     sqlite3_int64 iSize;
   940         -  fd = (sqlite3_file*)sqlite3_malloc(gQuota.sThisVfs.szOsFile +
   941         -                                     gQuota.sThisVfs.mxPathname+1);
   942         -  if( fd==0 ) return SQLITE_NOMEM;
   943         -  zFull = gQuota.sThisVfs.szOsFile + (char*)fd;
   944         -  rc = gQuota.pOrigVfs->xFullPathname(gQuota.pOrigVfs, zFilename,
   945         -                                      gQuota.sThisVfs.mxPathname+1, zFull);
          940  +  int nAlloc = gQuota.sThisVfs.szOsFile + gQuota.sThisVfs.mxPathname+2;
          941  +
          942  +  /* Allocate space for a file-handle and the full path for file zFilename */
          943  +  fd = (sqlite3_file *)sqlite3_malloc(nAlloc);
          944  +  if( fd==0 ){
          945  +    rc = SQLITE_NOMEM;
          946  +  }else{
          947  +    zFull = &((char *)fd)[gQuota.sThisVfs.szOsFile];
          948  +    rc = gQuota.pOrigVfs->xFullPathname(gQuota.pOrigVfs, zFilename,
          949  +        gQuota.sThisVfs.mxPathname+1, zFull);
          950  +  }
          951  +
   946    952     if( rc==SQLITE_OK ){
          953  +    zFull[strlen(zFull)+1] = '\0';
   947    954       rc = quotaOpen(&gQuota.sThisVfs, zFull, fd, 
   948    955                      SQLITE_OPEN_READONLY | SQLITE_OPEN_MAIN_DB, &outFlags);
   949         -  }
   950         -  if( rc==SQLITE_OK ){
   951         -    fd->pMethods->xFileSize(fd, &iSize);
   952         -    fd->pMethods->xClose(fd);
   953         -  }else if( rc==SQLITE_CANTOPEN ){
   954         -    quotaGroup *pGroup;
   955         -    quotaFile *pFile;
   956         -    quotaEnter();
   957         -    pGroup = quotaGroupFind(zFull);
   958         -    if( pGroup ){
   959         -      pFile = quotaFindFile(pGroup, zFull, 0);
   960         -      if( pFile ) quotaRemoveFile(pFile);
          956  +    if( rc==SQLITE_OK ){
          957  +      fd->pMethods->xFileSize(fd, &iSize);
          958  +      fd->pMethods->xClose(fd);
          959  +    }else if( rc==SQLITE_CANTOPEN ){
          960  +      quotaGroup *pGroup;
          961  +      quotaFile *pFile;
          962  +      quotaEnter();
          963  +      pGroup = quotaGroupFind(zFull);
          964  +      if( pGroup ){
          965  +        pFile = quotaFindFile(pGroup, zFull, 0);
          966  +        if( pFile ) quotaRemoveFile(pFile);
          967  +      }
          968  +      quotaLeave();
   961    969       }
   962         -    quotaLeave();
   963    970     }
          971  +
   964    972     sqlite3_free(fd);
   965    973     return rc;
   966    974   }
   967    975   
   968    976   /*
   969    977   ** Open a potentially quotaed file for I/O.
   970    978   */