/ Check-in [93a65776]
Login

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

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 93a65776dc8f496485e206a5eab11eeba579b5da
User & Date: mistachkin 2012-01-11 01:01:02
Context
2012-01-11
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
00:38
Make sure filenames handed to the VFS by the fake_big_file test procedure are double-zero terminated. check-in: d0a86860 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

  2502   2502   
  2503   2503       rc = winOpen(pDbFd->pVfs,
  2504   2504                    pShmNode->zFilename,             /* Name of the file (UTF-8) */
  2505   2505                    (sqlite3_file*)&pShmNode->hFile,  /* File handle here */
  2506   2506                    SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
  2507   2507                    0);
  2508   2508       if( SQLITE_OK!=rc ){
  2509         -      rc = SQLITE_CANTOPEN_BKPT;
  2510   2509         goto shm_open_err;
  2511   2510       }
  2512   2511   
  2513   2512       /* Check to see if another process is holding the dead-man switch.
  2514   2513       ** If not, truncate the file to zero length. 
  2515   2514       */
  2516   2515       if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
................................................................................
  2925   2924   */
  2926   2925   static int getTempname(int nBuf, char *zBuf){
  2927   2926     static char zChars[] =
  2928   2927       "abcdefghijklmnopqrstuvwxyz"
  2929   2928       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2930   2929       "0123456789";
  2931   2930     size_t i, j;
  2932         -  char zTempPath[MAX_PATH+1];
         2931  +  char zTempPath[MAX_PATH+2];
  2933   2932   
  2934   2933     /* It's odd to simulate an io-error here, but really this is just
  2935   2934     ** using the io-error infrastructure to test that SQLite handles this
  2936   2935     ** function failing. 
  2937   2936     */
  2938   2937     SimulateIOError( return SQLITE_IOERR );
  2939   2938   
................................................................................
  2968   2967       }
  2969   2968   #endif
  2970   2969     }
  2971   2970   
  2972   2971     /* Check that the output buffer is large enough for the temporary file 
  2973   2972     ** name. If it is not, return SQLITE_ERROR.
  2974   2973     */
  2975         -  if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){
         2974  +  if( (sqlite3Strlen30(zTempPath) + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){
  2976   2975       return SQLITE_ERROR;
  2977   2976     }
  2978   2977   
  2979   2978     for(i=sqlite3Strlen30(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
  2980   2979     zTempPath[i] = 0;
  2981   2980   
  2982         -  sqlite3_snprintf(nBuf-17, zBuf,
         2981  +  sqlite3_snprintf(nBuf-18, zBuf,
  2983   2982                      "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
  2984   2983     j = sqlite3Strlen30(zBuf);
  2985   2984     sqlite3_randomness(15, &zBuf[j]);
  2986   2985     for(i=0; i<15; i++, j++){
  2987   2986       zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
  2988   2987     }
  2989   2988     zBuf[j] = 0;
         2989  +  zBuf[j+1] = 0;
  2990   2990   
  2991   2991     OSTRACE(("TEMP FILENAME: %s\n", zBuf));
  2992   2992     return SQLITE_OK; 
  2993   2993   }
  2994   2994   
  2995   2995   /*
  2996   2996   ** Open a file.
................................................................................
  3015   3015     void *zConverted;              /* Filename in OS encoding */
  3016   3016     const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
  3017   3017     int cnt = 0;
  3018   3018   
  3019   3019     /* If argument zPath is a NULL pointer, this function is required to open
  3020   3020     ** a temporary file. Use this buffer to store the file name in.
  3021   3021     */
  3022         -  char zTmpname[MAX_PATH+1];     /* Buffer used to create temp filename */
         3022  +  char zTmpname[MAX_PATH+2];     /* Buffer used to create temp filename */
  3023   3023   
  3024   3024     int rc = SQLITE_OK;            /* Function Return Code */
  3025   3025   #if !defined(NDEBUG) || SQLITE_OS_WINCE
  3026   3026     int eType = flags&0xFFFFFF00;  /* Type of file to open */
  3027   3027   #endif
  3028   3028   
  3029   3029     int isExclusive  = (flags & SQLITE_OPEN_EXCLUSIVE);
................................................................................
  3074   3074     pFile->h = INVALID_HANDLE_VALUE;
  3075   3075   
  3076   3076     /* If the second argument to this function is NULL, generate a 
  3077   3077     ** temporary file name to use 
  3078   3078     */
  3079   3079     if( !zUtf8Name ){
  3080   3080       assert(isDelete && !isOpenJournal);
  3081         -    rc = getTempname(MAX_PATH+1, zTmpname);
         3081  +    rc = getTempname(MAX_PATH+2, zTmpname);
  3082   3082       if( rc!=SQLITE_OK ){
  3083   3083         return rc;
  3084   3084       }
  3085   3085       zUtf8Name = zTmpname;
  3086   3086     }
         3087  +
         3088  +  /* Database filenames are double-zero terminated if they are not
         3089  +  ** URIs with parameters.  Hence, they can always be passed into
         3090  +  ** sqlite3_uri_parameter().
         3091  +  */
         3092  +  assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) ||
         3093  +        zUtf8Name[strlen(zUtf8Name)+1]==0 );
  3087   3094   
  3088   3095     /* Convert the filename to the system encoding. */
  3089   3096     zConverted = convertUtf8Filename(zUtf8Name);
  3090   3097     if( zConverted==0 ){
  3091   3098       return SQLITE_IOERR_NOMEM;
  3092   3099     }
  3093   3100