Index: third_party/sqlite/src/src/prepare.c |
diff --git a/third_party/sqlite/src/src/prepare.c b/third_party/sqlite/src/src/prepare.c |
index a05e619f3ed596c360ebd2f829a1b0d2d4fa6ee3..5d1ae00d137867d8404238237f1cccbb21d7ce18 100644 |
--- a/third_party/sqlite/src/src/prepare.c |
+++ b/third_party/sqlite/src/src/prepare.c |
@@ -26,13 +26,13 @@ static void corruptSchema( |
){ |
sqlite3 *db = pData->db; |
if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){ |
+ char *z; |
if( zObj==0 ) zObj = "?"; |
- sqlite3SetString(pData->pzErrMsg, db, |
- "malformed database schema (%s)", zObj); |
- if( zExtra ){ |
- *pData->pzErrMsg = sqlite3MAppendf(db, *pData->pzErrMsg, |
- "%s - %s", *pData->pzErrMsg, zExtra); |
- } |
+ z = sqlite3_mprintf("malformed database schema (%s)", zObj); |
+ if( z && zExtra ) z = sqlite3_mprintf("%z - %s", z, zExtra); |
+ sqlite3DbFree(db, *pData->pzErrMsg); |
+ *pData->pzErrMsg = z; |
+ if( z==0 ) db->mallocFailed = 1; |
} |
pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT_BKPT; |
} |
@@ -67,7 +67,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){ |
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ |
if( argv[1]==0 ){ |
corruptSchema(pData, argv[0], 0); |
- }else if( argv[2] && argv[2][0] ){ |
+ }else if( sqlite3_strnicmp(argv[2],"create ",7)==0 ){ |
/* Call the parser to process a CREATE TABLE, INDEX or VIEW. |
** But because db->init.busy is set to 1, no VDBE code is generated |
** or executed. All the parser does is build the internal data |
@@ -98,8 +98,8 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){ |
} |
} |
sqlite3_finalize(pStmt); |
- }else if( argv[0]==0 ){ |
- corruptSchema(pData, 0, 0); |
+ }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){ |
+ corruptSchema(pData, argv[0], 0); |
}else{ |
/* If the SQL column is blank it means this is an index that |
** was created to be the PRIMARY KEY or to fulfill a UNIQUE |
@@ -224,7 +224,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ |
if( !sqlite3BtreeIsInReadTrans(pDb->pBt) ){ |
rc = sqlite3BtreeBeginTrans(pDb->pBt, 0); |
if( rc!=SQLITE_OK ){ |
- sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc)); |
+ sqlite3SetString(pzErrMsg, db, sqlite3ErrStr(rc)); |
goto initone_error_out; |
} |
openedTransaction = 1; |
@@ -394,9 +394,11 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){ |
int commit_internal = !(db->flags&SQLITE_InternChanges); |
assert( sqlite3_mutex_held(db->mutex) ); |
+ assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) ); |
assert( db->init.busy==0 ); |
rc = SQLITE_OK; |
db->init.busy = 1; |
+ ENC(db) = SCHEMA_ENC(db); |
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; |
rc = sqlite3InitOne(db, i, pzErrMsg); |
@@ -709,9 +711,12 @@ static int sqlite3LockAndPrepare( |
const char **pzTail /* OUT: End of parsed string */ |
){ |
int rc; |
- assert( ppStmt!=0 ); |
+ |
+#ifdef SQLITE_ENABLE_API_ARMOR |
+ if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; |
+#endif |
*ppStmt = 0; |
- if( !sqlite3SafetyCheckOk(db) ){ |
+ if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ |
return SQLITE_MISUSE_BKPT; |
} |
sqlite3_mutex_enter(db->mutex); |
@@ -818,9 +823,11 @@ static int sqlite3Prepare16( |
const char *zTail8 = 0; |
int rc = SQLITE_OK; |
- assert( ppStmt ); |
+#ifdef SQLITE_ENABLE_API_ARMOR |
+ if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; |
+#endif |
*ppStmt = 0; |
- if( !sqlite3SafetyCheckOk(db) ){ |
+ if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ |
return SQLITE_MISUSE_BKPT; |
} |
if( nBytes>=0 ){ |