aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2010-08-24 18:07:57 +0000
committerdrh <drh@noemail.net>2010-08-24 18:07:57 +0000
commit357b5f97bef088ea35304bbf2c07a27b4afe585d (patch)
treed14eebb0d901417c44196012993ba6e9f0e43c3b /src
parent9d13f116af52d4d8043ee20b101756caf6f530af (diff)
downloadsqlite-357b5f97bef088ea35304bbf2c07a27b4afe585d.tar.gz
sqlite-357b5f97bef088ea35304bbf2c07a27b4afe585d.zip
Change sqlite3_open_v2() to return SQLITE_MISUSE if the combination of bits
in the flags parameter is invalid. The documentation says the behavior in this situation is undefined - the documentation is unaltered by this code change. FossilOrigin-Name: 5e8101c5122336844ea920e6fbdace23e35b931f
Diffstat (limited to 'src')
-rw-r--r--src/main.c21
-rw-r--r--src/sqlite.h.in2
2 files changed, 21 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index b233c8473..c82a82e46 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1680,6 +1680,24 @@ static int openDatabase(
if( rc ) return rc;
#endif
+ /* Only allow sensible combinations of bits in the flags argument.
+ ** Throw an error if any non-sense combination is used. If we
+ ** do not block illegal combinations here, it could trigger
+ ** assert() statements in deeper layers. Sensible combinations
+ ** are:
+ **
+ ** 1: SQLITE_OPEN_READONLY
+ ** 2: SQLITE_OPEN_READWRITE
+ ** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
+ */
+ assert( SQLITE_OPEN_READONLY == 0x01 );
+ assert( SQLITE_OPEN_READWRITE == 0x02 );
+ assert( SQLITE_OPEN_CREATE == 0x04 );
+ testcase( (1<<(flags&7))==0x02 ); /* READONLY */
+ testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
+ testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
+ if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE;
+
if( sqlite3GlobalConfig.bCoreMutex==0 ){
isThreadsafe = 0;
}else if( flags & SQLITE_OPEN_NOMUTEX ){
@@ -1713,7 +1731,8 @@ static int openDatabase(
SQLITE_OPEN_SUBJOURNAL |
SQLITE_OPEN_MASTER_JOURNAL |
SQLITE_OPEN_NOMUTEX |
- SQLITE_OPEN_FULLMUTEX
+ SQLITE_OPEN_FULLMUTEX |
+ SQLITE_OPEN_WAL
);
/* Allocate the sqlite data structure */
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 39461aace..d2ea460f6 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -2264,7 +2264,7 @@ void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
** If the 3rd parameter to sqlite3_open_v2() is not one of the
** combinations shown above or one of the combinations shown above combined
** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
-** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags,
+** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
** then the behavior is undefined.
**
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection