aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/btree.c7
-rw-r--r--src/os.c13
-rw-r--r--src/os.h4
-rw-r--r--src/os_unix.c10
-rw-r--r--src/os_win.c9
-rw-r--r--src/pager.c9
-rw-r--r--src/sqlite.h.in13
-rw-r--r--src/test6.c13
-rw-r--r--src/test_async.c7
-rw-r--r--src/test_onefile.c17
10 files changed, 66 insertions, 36 deletions
diff --git a/src/btree.c b/src/btree.c
index 4c38882ea..99147fb84 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.426 2007/09/12 17:01:45 danielk1977 Exp $
+** $Id: btree.c,v 1.427 2007/09/17 07:02:57 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@@ -1158,7 +1158,8 @@ int sqlite3BtreeOpen(
&& zFilename && zFilename[0]
){
if( sqlite3SharedCacheEnabled ){
- char *zFullPathname = (char *)sqlite3_malloc(pVfs->mxPathname);
+ int nFullPathname = pVfs->mxPathname+1;
+ char *zFullPathname = (char *)sqlite3_malloc(nFullPathname);
sqlite3_mutex *mutexShared;
p->sharable = 1;
if( pSqlite ){
@@ -1168,7 +1169,7 @@ int sqlite3BtreeOpen(
sqlite3_free(p);
return SQLITE_NOMEM;
}
- sqlite3OsFullPathname(pVfs, zFilename, zFullPathname);
+ sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
mutexShared = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
sqlite3_mutex_enter(mutexShared);
for(pBt=sqlite3SharedCacheList; pBt; pBt=pBt->pNext){
diff --git a/src/os.c b/src/os.c
index bfc7e99bb..28de37da0 100644
--- a/src/os.c
+++ b/src/os.c
@@ -107,11 +107,16 @@ int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
int sqlite3OsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){
return pVfs->xAccess(pVfs, zPath, flags);
}
-int sqlite3OsGetTempname(sqlite3_vfs *pVfs, char *zBufOut){
- return pVfs->xGetTempname(pVfs, zBufOut);
+int sqlite3OsGetTempname(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut){
+ return pVfs->xGetTempname(pVfs, nBufOut, zBufOut);
}
-int sqlite3OsFullPathname(sqlite3_vfs *pVfs, const char *zPath, char *zPathOut){
- return pVfs->xFullPathname(pVfs, zPath, zPathOut);
+int sqlite3OsFullPathname(
+ sqlite3_vfs *pVfs,
+ const char *zPath,
+ int nPathOut,
+ char *zPathOut
+){
+ return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut);
}
void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
return pVfs->xDlOpen(pVfs, zPath);
diff --git a/src/os.h b/src/os.h
index d5edcaef8..554952df0 100644
--- a/src/os.h
+++ b/src/os.h
@@ -250,8 +250,8 @@ int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
int sqlite3OsAccess(sqlite3_vfs *, const char *, int);
-int sqlite3OsGetTempname(sqlite3_vfs *, char *);
-int sqlite3OsFullPathname(sqlite3_vfs *, const char *, char *);
+int sqlite3OsGetTempname(sqlite3_vfs *, int, char *);
+int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *);
void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
void sqlite3OsDlError(sqlite3_vfs *, int, char *);
void *sqlite3OsDlSym(sqlite3_vfs *, void *, const char *);
diff --git a/src/os_unix.c b/src/os_unix.c
index 30e2cbb26..2732f58e9 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -2474,7 +2474,7 @@ static int unixAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){
** by the calling process and must be big enough to hold at least
** pVfs->mxPathname bytes.
*/
-static int unixGetTempname(sqlite3_vfs *pVfs, char *zBuf){
+static int unixGetTempname(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
static const char *azDirs[] = {
0,
"/var/tmp",
@@ -2507,6 +2507,7 @@ static int unixGetTempname(sqlite3_vfs *pVfs, char *zBuf){
}
do{
assert( pVfs->mxPathname==MAX_PATHNAME );
+ assert( nBuf>=MAX_PATHNAME );
sqlite3_snprintf(MAX_PATHNAME-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
j = strlen(zBuf);
sqlite3Randomness(15, &zBuf[j]);
@@ -2528,7 +2529,12 @@ static int unixGetTempname(sqlite3_vfs *pVfs, char *zBuf){
** (in this case, MAX_PATHNAME bytes). The full-path is written to
** this buffer before returning.
*/
-static int unixFullPathname(sqlite3_vfs *pVfs, const char *zPath, char *zOut){
+static int unixFullPathname(
+ sqlite3_vfs *pVfs, /* Pointer to vfs object */
+ const char *zPath, /* Possibly relative input path */
+ int nOut, /* Size of output buffer in bytes */
+ char *zOut /* Output buffer */
+){
/* It's odd to simulate an io-error here, but really this is just
** using the io-error infrastructure to test that SQLite handles this
diff --git a/src/os_win.c b/src/os_win.c
index f140054f3..4eac10b86 100644
--- a/src/os_win.c
+++ b/src/os_win.c
@@ -1267,7 +1267,7 @@ static int winAccess(
** Create a temporary file name in zBuf. zBuf must be big enough to
** hold at pVfs->mxPathname characters.
*/
-static int winGetTempname(sqlite3_vfs *pVfs, char *zBuf){
+static int winGetTempname(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
static char zChars[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -1319,9 +1319,10 @@ static int winGetTempname(sqlite3_vfs *pVfs, char *zBuf){
** bytes in size.
*/
static int winFullPathname(
- sqlite3_vfs *pVfs,
- const char *zRelative,
- char *zFull
+ sqlite3_vfs *pVfs, /* Pointer to vfs object */
+ const char *zRelative, /* Possibly relative input path */
+ int nFull, /* Size of output buffer in bytes */
+ char *zFull /* Output buffer */
){
#if defined(__CYGWIN__)
diff --git a/src/pager.c b/src/pager.c
index ddd923691..c442365e4 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.389 2007/09/17 06:06:39 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.390 2007/09/17 07:02:57 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -2039,7 +2039,8 @@ int sqlite3PagerOpen(
*ppPager = 0;
/* Compute the full pathname */
- zPathname = sqlite3_malloc(pVfs->mxPathname+1);
+ nPathname = pVfs->mxPathname+1;
+ zPathname = sqlite3_malloc(nPathname);
if( zPathname==0 ){
return SQLITE_NOMEM;
}
@@ -2051,10 +2052,10 @@ int sqlite3PagerOpen(
}else
#endif
{
- rc = sqlite3OsFullPathname(pVfs, zFilename, zPathname);
+ rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
}
}else{
- rc = sqlite3OsGetTempname(pVfs, zPathname);
+ rc = sqlite3OsGetTempname(pVfs, nPathname, zPathname);
}
if( rc!=SQLITE_OK ){
sqlite3_free(zPathname);
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index b9d96c231..175dbfdc7 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
-** @(#) $Id: sqlite.h.in,v 1.260 2007/09/17 06:06:39 danielk1977 Exp $
+** @(#) $Id: sqlite.h.in,v 1.261 2007/09/17 07:02:57 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -662,7 +662,12 @@ typedef struct sqlite3_mutex sqlite3_mutex;
** directory.
**
** SQLite will always allocate at least mxPathname+1 byte for
-** the output buffers for xGetTempname and xFullPathname.
+** the output buffers for xGetTempname and xFullPathname. The exact
+** size of the output buffer is also passed as a parameter to both
+** methods. If the output buffer is not large enough, SQLITE_CANTOPEN
+** should be returned. As this is handled as a fatal error by SQLite,
+** vfs implementations should endevour to prevent this by setting
+** mxPathname to a sufficiently large value.
**
** The xRandomness(), xSleep(), and xCurrentTime() interfaces
** are not strictly a part of the filesystem, but they are
@@ -687,8 +692,8 @@ struct sqlite3_vfs {
int flags, int *pOutFlags);
int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
int (*xAccess)(sqlite3_vfs*, const char *zName, int flags);
- int (*xGetTempname)(sqlite3_vfs*, char *zOut);
- int (*xFullPathname)(sqlite3_vfs*, const char *zName, char *zOut);
+ int (*xGetTempname)(sqlite3_vfs*, int nOut, char *zOut);
+ int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol);
diff --git a/src/test6.c b/src/test6.c
index 4251fc932..c0456ca86 100644
--- a/src/test6.c
+++ b/src/test6.c
@@ -568,13 +568,18 @@ static int cfAccess(sqlite3_vfs *pCfVfs, const char *zPath, int flags){
sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData;
return pVfs->xAccess(pVfs, zPath, flags);
}
-static int cfGetTempname(sqlite3_vfs *pCfVfs, char *zBufOut){
+static int cfGetTempname(sqlite3_vfs *pCfVfs, int nBufOut, char *zBufOut){
sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData;
- return pVfs->xGetTempname(pVfs, zBufOut);
+ return pVfs->xGetTempname(pVfs, nBufOut, zBufOut);
}
-static int cfFullPathname(sqlite3_vfs *pCfVfs, const char *zPath, char *zPathOut){
+static int cfFullPathname(
+ sqlite3_vfs *pCfVfs,
+ const char *zPath,
+ int nPathOut,
+ char *zPathOut
+){
sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData;
- return pVfs->xFullPathname(pVfs, zPath, zPathOut);
+ return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut);
}
static void *cfDlOpen(sqlite3_vfs *pCfVfs, const char *zPath){
sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData;
diff --git a/src/test_async.c b/src/test_async.c
index ee8d80c95..b01822371 100644
--- a/src/test_async.c
+++ b/src/test_async.c
@@ -990,9 +990,9 @@ static int asyncAccess(sqlite3_vfs *pAsyncVfs, const char *zName, int flags){
return ret;
}
-static int asyncGetTempname(sqlite3_vfs *pAsyncVfs, char *zBufOut){
+static int asyncGetTempname(sqlite3_vfs *pAsyncVfs, int nBufOut, char *zBufOut){
sqlite3_vfs *pVfs = (sqlite3_vfs *)pAsyncVfs->pAppData;
- return pVfs->xGetTempname(pVfs, zBufOut);
+ return pVfs->xGetTempname(pVfs, nBufOut, zBufOut);
}
/*
@@ -1001,11 +1001,12 @@ static int asyncGetTempname(sqlite3_vfs *pAsyncVfs, char *zBufOut){
static int asyncFullPathname(
sqlite3_vfs *pAsyncVfs,
const char *zPath,
+ int nPathOut,
char *zPathOut
){
int rc;
sqlite3_vfs *pVfs = (sqlite3_vfs *)pAsyncVfs->pAppData;
- rc = sqlite3OsFullPathname(pVfs, zPath, zPathOut);
+ rc = sqlite3OsFullPathname(pVfs, zPath, nPathOut, zPathOut);
/* Because of the way intra-process file locking works, this backend
** needs to return a canonical path. The following block assumes the
diff --git a/src/test_onefile.c b/src/test_onefile.c
index 700dfcd35..d7e19de64 100644
--- a/src/test_onefile.c
+++ b/src/test_onefile.c
@@ -163,8 +163,8 @@ static int tmpDeviceCharacteristics(sqlite3_file*);
static int fsOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int fsDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int fsAccess(sqlite3_vfs*, const char *zName, int flags);
-static int fsGetTempname(sqlite3_vfs*, char *zOut);
-static int fsFullPathname(sqlite3_vfs*, const char *zName, char *zOut);
+static int fsGetTempname(sqlite3_vfs*, int nOut, char *zOut);
+static int fsFullPathname(sqlite3_vfs*, const char *zName, int nOut,char *zOut);
static void *fsDlOpen(sqlite3_vfs*, const char *zFilename);
static void fsDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
static void *fsDlSym(sqlite3_vfs*,void*, const char *zSymbol);
@@ -726,9 +726,9 @@ static int fsAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){
** temporary file. zBufOut is guaranteed to point to a buffer of
** at least (FS_MAX_PATHNAME+1) bytes.
*/
-static int fsGetTempname(sqlite3_vfs *pVfs, char *zBufOut){
+static int fsGetTempname(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut){
sqlite3_vfs *pParent = ((fs_vfs_t *)pVfs)->pParent;
- return pParent->xGetTempname(pParent, zBufOut);
+ return pParent->xGetTempname(pParent, nBufOut, zBufOut);
}
/*
@@ -736,9 +736,14 @@ static int fsGetTempname(sqlite3_vfs *pVfs, char *zBufOut){
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (FS_MAX_PATHNAME+1) bytes.
*/
-static int fsFullPathname(sqlite3_vfs *pVfs, const char *zPath, char *zOut){
+static int fsFullPathname(
+ sqlite3_vfs *pVfs, /* Pointer to vfs object */
+ const char *zPath, /* Possibly relative input path */
+ int nOut, /* Size of output buffer in bytes */
+ char *zOut /* Output buffer */
+){
sqlite3_vfs *pParent = ((fs_vfs_t *)pVfs)->pParent;
- return pParent->xFullPathname(pParent, zPath, zOut);
+ return pParent->xFullPathname(pParent, zPath, nOut, zOut);
}
/*