]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Only require double-zero terminators on database filenames, not any every
authordrh <drh@noemail.net>
Tue, 10 Jan 2012 23:18:38 +0000 (23:18 +0000)
committerdrh <drh@noemail.net>
Tue, 10 Jan 2012 23:18:38 +0000 (23:18 +0000)
files supplied to the xOpen method.  This backs out [2544f233f1].  Also
refactor the fillInUnixFile() routine in os_unix.c to reduce the number
of parameters.

FossilOrigin-Name: cb774b26e13745cfad0d76a71e47466d703e0007

1  2 
manifest
manifest.uuid
src/os_unix.c
src/pager.c
src/test3.c
src/test_multiplex.c
src/util.c

diff --cc manifest
index 95259aac19436845e2964d0175e4887eabec03a2,ff74ba20b04f914f10a1e5ac659542a72f77d297..da7428de0bd6e62c367fdee430f19a5c7f068f69
+++ b/manifest
@@@ -1,5 -1,5 +1,5 @@@
- C Refactor\ssqlite3OsFileControlNoFail()\sinto\ssqlite3FileControlHint().
- D 2012-01-10T17:59:59.268
 -C Add\sfunction\ssqlite3OsFileControlNoFail(),\swhich\sis\sthe\ssame\sas\ssqlite3OsFileControl()\sexcept\sthat\sit\sdoes\snot\ssimulate\sOOM\serrors.\sThis\ssaves\sadding\scalls\sto\sthe\sBenignMalloc()\sfunctions\saround\seach\sof\sthe\sinvocations\sof\ssqliteOsFileControl()\sthat\signore\sthe\sreturn\scode.
 -D 2012-01-10T16:56:39.621
++C Only\srequire\sdouble-zero\sterminators\son\sdatabase\sfilenames,\snot\sany\severy\nfiles\ssupplied\sto\sthe\sxOpen\smethod.\s\sThis\sbacks\sout\s[2544f233f1].\s\sAlso\nrefactor\sthe\sfillInUnixFile()\sroutine\sin\sos_unix.c\sto\sreduce\sthe\snumber\nof\sparameters.
++D 2012-01-10T23:18:38.025
  F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
  F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07
  F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@@ -162,13 -162,13 +162,13 @@@ F src/mutex_os2.c 882d735098c07c8c6a547
  F src/mutex_unix.c c3a4e00f96ba068a8dbef34084465979aaf369cc
  F src/mutex_w32.c 5e54f3ba275bcb5d00248b8c23107df2e2f73e33
  F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
 -F src/os.c dedfe4786cc4a88033bbf43fcf1fb01cbec03dcc
 -F src/os.h 7a24446bcd9834d868b2bc303ec3bd38e64e04bc
 +F src/os.c e1acdc09ff3ac2412945cca9766e2dcf4675f31c
 +F src/os.h a2219c3b05ce31230bb000fdc4f1a542b33ee649
  F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
  F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
--F src/os_unix.c 2ad4366b3c41dc813345d6dbb3cab97d62d60b96
++F src/os_unix.c 657672fab2580a84116c140b36ee3d6b6fc75b4e
  F src/os_win.c e344ccb73aaeb5caab2c3419fba2857f914198d7
- F src/pager.c 355f00af21d490a88e2e2e6aec26237a621de1be
 -F src/pager.c e7c940ef4a3bad34c9c44ac429257fcf301b828f
++F src/pager.c 99ee9e52e48bd42bd7523968017c057b93d75df9
  F src/pager.h 5cd760857707529b403837d813d86b68938d6183
  F src/parse.y fabb2e7047417d840e6fdb3ef0988a86849a08ba
  F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
@@@ -191,7 -191,7 +191,7 @@@ F src/table.c 2cd62736f845d82200acfa128
  F src/tclsqlite.c bd86070f52ae3f77a2e6b3b065ff03adb9140bfa
  F src/test1.c 1b1e514e85ffe7152b02cba38bd0a1ce8cd56113
  F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31
--F src/test3.c 124ff9735fb6bb7d41de180d6bac90e7b1509432
++F src/test3.c 91d3f1a09cfae3533ef17d8b484a160f3d1f1a21
  F src/test4.c d1e5a5e904d4b444cf572391fdcb017638e36ff7
  F src/test5.c e1a19845625144caf038031234a12185e40d315c
  F src/test6.c cf6ab27a59e1ab64b011bb251ba600131e803e59
@@@ -214,7 -214,7 +214,7 @@@ F src/test_intarray.h 489edb9068bb92658
  F src/test_journal.c 2c06e4be6584d51b935dc8b353980a9388de62ef
  F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e
  F src/test_malloc.c 8d416f29ad8573f32601f6056c9d2b17472e9ad5
--F src/test_multiplex.c 6415713a7f36caa91d27fc9a53afbee235e65ab6
++F src/test_multiplex.c 67c210e2cdd63c4962c5cb20bd8fd2fd4d7a8410
  F src/test_multiplex.h e99c571bc4968b7a9363b661481f3934bfead61d
  F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e
  F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec
@@@ -238,7 -238,7 +238,7 @@@ F src/tokenize.c 1e86210d3976717a19238e
  F src/trigger.c ee7e178fb9188f44b532cebd449a7c1df90fb684
  F src/update.c d3076782c887c10e882996550345da9c4c9f9dea
  F src/utf.c 890c67dcfcc7a74623c95baac7535aadfe265e84
--F src/util.c d124c1f192bdcac733908fadd186f943788e7d2b
++F src/util.c 9e07bd67dfafe9c75b1da78c87ba030cebbb5388
  F src/vacuum.c 0c0ba2242355c6048d65e2b333abe0f7c06348fa
  F src/vdbe.c 64e3fc0bb56c54ceac3cc1d1e65257bfda21550e
  F src/vdbe.h 18f581cac1f4339ec3299f3e0cc6e11aec654cdb
@@@ -986,7 -986,7 +986,7 @@@ F tool/tostr.awk e75472c2f98dd76e06b8c9
  F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
  F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
  F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
- P 2544f233f1041a42bbdbb5413d2bc92b2a2e0397
- R 90d4428386a9e255bbb4a91446028664
 -P 7f852ac6435f1c9e25b07f816cca5ba40484579e
 -R 0386e0f2452004fbea4274e17c048ecf
 -U dan
 -Z d0553b98b27ed93d2ef4aa9f634cdd90
++P 722735a4f316630c907149f08d3d7dccc0facd9a af59b182d797642e5ec3ddf291cf62662a136bd1
++R 0517e1b31ad3aca42e254a546daa87b4
 +U drh
- Z 45ce0d11ceb0dbbfe189c0194c677275
++Z c7868cbe469d9c92bafb5dccf1093985
diff --cc manifest.uuid
index 0cc609493075640821d9a332d8a2192196b8d1e5,01a50bf8d39941d73c99bb9d5d1c0b57fda26c36..3bcb2f9c7ba9f37e08837dd3f6a0f24e4b07d723
@@@ -1,1 -1,1 +1,1 @@@
- 722735a4f316630c907149f08d3d7dccc0facd9a
 -af59b182d797642e5ec3ddf291cf62662a136bd1
++cb774b26e13745cfad0d76a71e47466d703e0007
diff --cc src/os_unix.c
index 1275ae10c76b856164e283c2b5a9ded32d0a993e,1275ae10c76b856164e283c2b5a9ded32d0a993e..13faac3a5e33e8c134af991d31a3320d7c8bd17d
@@@ -225,7 -225,7 +225,6 @@@ struct unixFile 
    unsigned fsFlags;                   /* cached details from statfs() */
  #endif
  #if OS_VXWORKS
--  int isDelete;                       /* Delete on close if true */
    struct vxworksFileId *pId;          /* Unique file ID */
  #endif
  #ifndef NDEBUG
  # define UNIXFILE_DIRSYNC    0x00
  #endif
  #define UNIXFILE_PSOW        0x10     /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
++#define UNIXFILE_DELETE      0x20     /* Delete on close */
++#define UNIXFILE_URI         0x40     /* Filename might have query parameters */
++#define UNIXFILE_NOLOCK      0x80     /* Do no file locking */
  
  /*
  ** Include code that is common to all os_*.c files
@@@ -1765,7 -1765,7 +1767,7 @@@ static int closeUnixFile(sqlite3_file *
    }
  #if OS_VXWORKS
    if( pFile->pId ){
--    if( pFile->isDelete ){
++    if( pFile->ctrlFlags & UNIXFILE_DELETE ){
        osUnlink(pFile->pId->zCanonicalName);
      }
      vxworksReleaseFileId(pFile->pId);
@@@ -4555,12 -4555,12 +4557,9 @@@ typedef const sqlite3_io_methods *(*fin
  static int fillInUnixFile(
    sqlite3_vfs *pVfs,      /* Pointer to vfs object */
    int h,                  /* Open file descriptor of file being opened */
--  int syncDir,            /* True to sync directory on first sync */
    sqlite3_file *pId,      /* Write to the unixFile structure here */
    const char *zFilename,  /* Name of the file being opened */
--  int noLock,             /* Omit locking if true */
--  int isDelete,           /* Delete on close if true */
--  int isReadOnly          /* True if the file is opened read-only */
++  int ctrlFlags           /* Zero or more UNIXFILE_* values */
  ){
    const sqlite3_io_methods *pLockingStyle;
    unixFile *pNew = (unixFile *)pId;
  
    assert( pNew->pInode==NULL );
  
--  /* Parameter isDelete is only used on vxworks. Express this explicitly 
--  ** here to prevent compiler warnings about unused parameters.
--  */
--  UNUSED_PARAMETER(isDelete);
--
    /* Usually the path zFilename should not be a relative pathname. The
    ** exception is when opening the proxy "conch" file in builds that
    ** include the special Apple locking styles.
  #endif
  
    /* No locking occurs in temporary files */
--  assert( zFilename!=0 || noLock );
++  assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
  
    OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
    pNew->h = h;
    pNew->pVfs = pVfs;
    pNew->zPath = zFilename;
--  pNew->ctrlFlags = 0;
--  if( sqlite3_uri_boolean(zFilename, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
++  pNew->ctrlFlags = (u8)ctrlFlags;
++  if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
++                           "psow", SQLITE_POWERSAFE_OVERWRITE) ){
      pNew->ctrlFlags |= UNIXFILE_PSOW;
    }
    if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
      pNew->ctrlFlags |= UNIXFILE_EXCL;
    }
--  if( isReadOnly ){
--    pNew->ctrlFlags |= UNIXFILE_RDONLY;
--  }
--  if( syncDir ){
--    pNew->ctrlFlags |= UNIXFILE_DIRSYNC;
--  }
  
  #if OS_VXWORKS
    pNew->pId = vxworksFindFileId(zFilename);
    if( pNew->pId==0 ){
--    noLock = 1;
++    ctrlFlags |= UNIXFILE_NOLOCK;
      rc = SQLITE_NOMEM;
    }
  #endif
  
--  if( noLock ){
++  if( ctrlFlags & UNIXFILE_NOLOCK ){
      pLockingStyle = &nolockIoMethods;
    }else{
      pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
      osUnlink(zFilename);
      isDelete = 0;
    }
--  pNew->isDelete = isDelete;
++  if( isDelete ) pNew->ctrlFlags |= UNIXFILE_DELETE;
  #endif
    if( rc!=SQLITE_OK ){
      if( h>=0 ) robust_close(pNew, h, __LINE__);
@@@ -4799,18 -4799,18 +4788,19 @@@ static int unixGetTempname(int nBuf, ch
    /* Check that the output buffer is large enough for the temporary file 
    ** name. If it is not, return SQLITE_ERROR.
    */
--  if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 17) >= (size_t)nBuf ){
++  if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){
      return SQLITE_ERROR;
    }
  
    do{
--    sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
++    sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
      j = (int)strlen(zBuf);
      sqlite3_randomness(15, &zBuf[j]);
      for(i=0; i<15; i++, j++){
        zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
      }
      zBuf[j] = 0;
++    zBuf[j+1] = 0;
    }while( osAccess(zBuf,0)==0 );
    return SQLITE_OK;
  }
@@@ -4989,6 -4989,6 +4979,7 @@@ static int unixOpen
    int eType = flags&0xFFFFFF00;  /* Type of file to open */
    int noLock;                    /* True to omit locking primitives */
    int rc = SQLITE_OK;            /* Function Return Code */
++  int ctrlFlags = 0;             /* UNIXFILE_* flags */
  
    int isExclusive  = (flags & SQLITE_OPEN_EXCLUSIVE);
    int isDelete     = (flags & SQLITE_OPEN_DELETEONCLOSE);
    /* If argument zPath is a NULL pointer, this function is required to open
    ** a temporary file. Use this buffer to store the file name in.
    */
--  char zTmpname[MAX_PATHNAME+1];
++  char zTmpname[MAX_PATHNAME+2];
    const char *zName = zPath;
  
    /* Check the following statements are true: 
        }
      }
      p->pUnused = pUnused;
++
++    /* Database filenames are double-zero terminated if they are not
++    ** URIs with parameters.  Hence, they can always be passed into
++    ** sqlite3_uri_parameter(). */
++    assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
++
    }else if( !zName ){
      /* If zName is NULL, the upper layer is requesting a temp file. */
      assert(isDelete && !syncDir);
--    rc = unixGetTempname(MAX_PATHNAME+1, zTmpname);
++    rc = unixGetTempname(MAX_PATHNAME+2, zTmpname);
      if( rc!=SQLITE_OK ){
        return rc;
      }
      zName = zTmpname;
++
++    /* Generated temporary filenames are always double-zero terminated
++    ** for use by sqlite3_uri_parameter(). */
++    assert( zName[strlen(zName)+1]==0 );
    }
  
    /* Determine the value of the flags parameter passed to POSIX function
      ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
    }
  #endif
--  
++
++  /* Set up appropriate ctrlFlags */
++  if( isDelete )                ctrlFlags |= UNIXFILE_DELETE;
++  if( isReadonly )              ctrlFlags |= UNIXFILE_RDONLY;
++  if( noLock )                  ctrlFlags |= UNIXFILE_NOLOCK;
++  if( syncDir )                 ctrlFlags |= UNIXFILE_DIRSYNC;
++  if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
++
  #if SQLITE_ENABLE_LOCKING_STYLE
  #if SQLITE_PREFER_PROXY_LOCKING
    isAutoProxy = 1;
        useProxy = !(fsInfo.f_flags&MNT_LOCAL);
      }
      if( useProxy ){
--      rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
--                          isDelete, isReadonly);
++      rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
        if( rc==SQLITE_OK ){
          rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
          if( rc!=SQLITE_OK ){
    }
  #endif
    
--  rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
--                      isDelete, isReadonly);
++  rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
++
  open_finished:
    if( rc!=SQLITE_OK ){
      sqlite3_free(p->pUnused);
@@@ -5862,7 -5862,7 +5869,7 @@@ static int proxyCreateUnixFile
    pUnused->flags = openFlags;
    pNew->pUnused = pUnused;
    
--  rc = fillInUnixFile(&dummyVfs, fd, 0, (sqlite3_file*)pNew, path, 0, 0, 0);
++  rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0);
    if( rc==SQLITE_OK ){
      *ppFile = pNew;
      return SQLITE_OK;
diff --cc src/pager.c
Simple merge
diff --cc src/test3.c
index 4eabdccfd6527dfb999d707b08af1ccb6eaacd58,4eabdccfd6527dfb999d707b08af1ccb6eaacd58..9bac2cac13cfec08ebe74aacc00cb3c7bfeedb6c
@@@ -66,6 -66,6 +66,8 @@@ static int btree_open
    Btree *pBt;
    int rc, nCache;
    char zBuf[100];
++  int n;
++  char *zFilename;
    if( argc!=3 ){
      Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
         " FILENAME NCACHE FLAGS\"", 0);
      sDb.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
      sqlite3_mutex_enter(sDb.mutex);
    }
--  rc = sqlite3BtreeOpen(sDb.pVfs, argv[1], &sDb, &pBt, 0, 
++  n = strlen(argv[1]);
++  zFilename = sqlite3_malloc( n+2 );
++  if( zFilename==0 ) return TCL_ERROR;
++  memcpy(zFilename, argv[1], n+1);
++  zFilename[n+1] = 0;
++  rc = sqlite3BtreeOpen(sDb.pVfs, zFilename, &sDb, &pBt, 0, 
       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB);
++  sqlite3_free(zFilename);
    if( rc!=SQLITE_OK ){
      Tcl_AppendResult(interp, errorName(rc), 0);
      return TCL_ERROR;
index d21b1a813ec9265aed0685358ebd132419a56641,d21b1a813ec9265aed0685358ebd132419a56641..1ae5cd477461e5cc57981f3f13859bc0e25f7395
@@@ -512,13 -512,13 +512,14 @@@ static int multiplexOpen
    }
  
    if( rc==SQLITE_OK ){
++    const char *zUri = (flags & SQLITE_OPEN_URI) ? zName : 0;
      /* assign pointers to extra space allocated */
      memset(pGroup, 0, sz);
      pMultiplexOpen->pGroup = pGroup;
      pGroup->bEnabled = -1;
--    pGroup->bTruncate = sqlite3_uri_boolean(zName, "truncate", 
--                                 (flags & SQLITE_OPEN_MAIN_DB)==0);
--    pGroup->szChunk = sqlite3_uri_int64(zName, "chunksize",
++    pGroup->bTruncate = sqlite3_uri_boolean(zUri, "truncate", 
++                                   (flags & SQLITE_OPEN_MAIN_DB)==0);
++    pGroup->szChunk = sqlite3_uri_int64(zUri, "chunksize",
                                          SQLITE_MULTIPLEX_CHUNK_SIZE);
      pGroup->szChunk = (pGroup->szChunk+0xffff)&~0xffff;
      if( zName ){
diff --cc src/util.c
index 6ff791a80e44718da9cf732fc1316f3658a72689,6ff791a80e44718da9cf732fc1316f3658a72689..fd3c858ab73358f8e6b112886c3b60c07cde919c
@@@ -1164,10 -1164,10 +1164,6 @@@ int sqlite3AbsInt32(int x)
  ** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
  ** do the suffix shortening regardless of URI parameter.
  **
--** Assume that zBaseFilename contains two \000 terminator bytes (so that
--** it can be harmlessly passed into sqlite3_uri_parameter()) and copy both
--** zero terminator bytes into the end of the revised name.
--**
  ** Examples:
  **
  **     test.db-journal    =>   test.nal
  **     test.db-mj7f3319fa =>   test.9fa
  */
  void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
--  assert( z[strlen(z)+1]==0 );  /* z[] has no query parameters */
  #if SQLITE_ENABLE_8_3_NAMES<2
    if( sqlite3_uri_boolean(zBaseFilename, "8_3_names", 0) )
  #endif
      int i, sz;
      sz = sqlite3Strlen30(z);
      for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
--    if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 5);
++    if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4);
    }
  }
  #endif