Correct the internal logic for SQLITE_DBCONFIG_DEFENSIVE.

FossilOrigin-Name: 76094345821246c887a31a234b339d03a78eddbb9fab33b06c3c20797c038349
This commit is contained in:
drh 2018-11-03 17:31:48 +00:00
parent a296cda016
commit 0f1c2eb5f2
8 changed files with 39 additions and 21 deletions

View File

@ -1,5 +1,5 @@
C Add\sthe\sSQLITE_DBCONFIG_DEFENSIVE\sflag.
D 2018-11-03T16:09:59.962
C Correct\sthe\sinternal\slogic\sfor\sSQLITE_DBCONFIG_DEFENSIVE.
D 2018-11-03T17:31:48.414
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in edbb6e20bb1decf65f6c64c9e61004a69bdf8afb39cdce5337c916b03dfcd1e3
@ -445,17 +445,17 @@ F src/auth.c 0fac71038875693a937e506bceb492c5f136dd7b1249fbd4ae70b4e8da14f9df
F src/backup.c 78d3cecfbe28230a3a9a1793e2ead609f469be43e8f486ca996006be551857ab
F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
F src/btree.c 41ab526796e7f3cc6e4c6d096c90ad35f0d3d1fe65964dcc0c4fddbbc7ad349d
F src/btree.c 3ef104ecae8b1b5f0458be1f5fa7c1ecf25fdc322a9d63bb8151f89eb32d381e
F src/btree.h febb2e817be499570b7a2e32a9bbb4b607a9234f6b84bb9ae84916d4806e96f2
F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd96
F src/build.c f5d49f97ab567b99fcc7ef8512cf0e61a662ba442a5d1fa8273edbc7575b92d4
F src/build.c 55f10596094e8a151df634308507cf397713fe96c42420a8aeef3b18be7eddac
F src/callback.c 789bd33d188146f66c0dd8306472a72d1c05f71924b24a91caf6bd45cf9aba73
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 109e58d00f62e8e71ee1eb5944ac18b90171c928ab2e082e058056e1137cc20b
F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957
F src/dbpage.c ada9bc6964bb68e4c128df70cb0938faaa214e1a0e1d730ea6b13c5e1fde9a45
F src/dbstat.c e042b0e7833fdacf2d5ea92c6b536962fea6aeed8b7287ca87ddfa3412bd9564
F src/delete.c 2ddd40f4b04647e85e4e8665e552b96971cd0026f7e6431ac9c1ce249d1d9161
F src/delete.c e1ac11c062a4a2ed29a9e9a63f4cbc7f0330291ae276d768b26fb2c5152cc3b4
F src/expr.c 9aacc0b72348ba90010b672dcbbbe2fa56e1182043bc917a3a147b2bc57a5497
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 972a4ba14296bef2303a0abbad1e3d82bc3c61f9e6ce4e8e9528bdee68748812
@ -509,12 +509,12 @@ F src/shell.c.in 060ccc327959bdc85c895015eb382017fd0cd000ebd47b7e8dda42f8aab0b66
F src/sqlite.h.in 1383b2fbce61bd3634caeafb2513205326a297e988ea749d4f6dec7da7a281c9
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683
F src/sqliteInt.h 16a6fe6475b4452dc7250afb40303f7cc3065024bab7ef412a9284247aac281c
F src/sqliteInt.h 8aef40f6e756120d51de73537dbdcd624f2b2b028fc59baad85e38a83e35d838
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
F src/tclsqlite.c e72862a271348d779672b45a730c33fd0c535e630ff927e8ce4a0c908d1d28c6
F src/test1.c e89148fdb0b3aa92af609669078c219d7b26bf442418b547f0db79d82a7d82f9
F src/test1.c b95363b0bc9e1ecc61964ca5a22c137422af4808a54a7bbb1a4f7d6d6257f704
F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
F src/test3.c 61798bb0d38b915067a8c8e03f5a534b431181f802659a6616f9b4ff7d872644
F src/test4.c 18ec393bb4d0ad1de729f0b94da7267270f3d8e6
@ -1005,7 +1005,7 @@ F test/incrvacuum.test b729aab1d4983037da57e66c20dfd7458561a85626dcf824f60175e35
F test/incrvacuum2.test 7d26cfda66c7e55898d196de54ac4ec7d86a4e3d
F test/incrvacuum3.test 75256fb1377e7c39ef2de62bfc42bbff67be295a
F test/incrvacuum_ioerr.test 6ae2f783424e47a0033304808fe27789cf93e635
F test/index.test fe3c7a1aad82af92623747e9c3f3aa94ccd51238
F test/index.test 5131c0106a6d0c892c5f438f0630e1b4361370c393ba8a000dd0dcaa2b3bf1de
F test/index2.test f835d5e13ca163bd78c4459ca15fd2e4ed487407
F test/index3.test 81bc47890b8abfb181bc35f8d10b56c069803386
F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6
@ -1775,10 +1775,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P dcb8c73594ea6b12bad98dc883a585d3e6b925c2ead267dc40332b3d266db5e8
R 70fb126ec78ede93e02159f3b0e08576
T *branch * dbconfig-defensive
T *sym-dbconfig-defensive *
T -sym-trunk *
P af3f29d49359af2291b1d9e06e0db76fd000fbd24b4ac84d2668a0d1322efd83
R 91b44778ed04a421f8e68340d094e060
U drh
Z 063598bbdddb8e4a121c6e32c0dbaf4a
Z ed3bd4f0fcf1321ed314532603a51952

View File

@ -1 +1 @@
af3f29d49359af2291b1d9e06e0db76fd000fbd24b4ac84d2668a0d1322efd83
76094345821246c887a31a234b339d03a78eddbb9fab33b06c3c20797c038349

View File

@ -3112,9 +3112,7 @@ static int lockBtree(BtShared *pBt){
pageSize-usableSize);
return rc;
}
if( (pBt->db->flags & (SQLITE_WriteSchema|SQLITE_Defensive))==0
&& nPage>nPageFile
){
if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
rc = SQLITE_CORRUPT_BKPT;
goto page1_init_failed;
}

View File

@ -797,6 +797,20 @@ int sqlite3TwoPartName(
return iDb;
}
/*
** True if PRAGMA writable_schema is ON
*/
int sqlite3WritableSchema(sqlite3 *db){
testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==0 );
testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==
SQLITE_WriteSchema );
testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==
SQLITE_Defensive );
testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==
(SQLITE_WriteSchema|SQLITE_Defensive) );
return (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==SQLITE_WriteSchema;
}
/*
** This routine is used to check if the UTF-8 string zName is a legal
** unqualified name for a new schema object (table, index, view or
@ -806,7 +820,7 @@ int sqlite3TwoPartName(
*/
int sqlite3CheckObjectName(Parse *pParse, const char *zName){
if( !pParse->db->init.busy && pParse->nested==0
&& (pParse->db->flags & (SQLITE_WriteSchema|SQLITE_Defensive))==0
&& sqlite3WritableSchema(pParse->db)==0
&& 0==sqlite3StrNICmp(zName, "sqlite_", 7) ){
sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s", zName);
return SQLITE_ERROR;

View File

@ -63,8 +63,8 @@ int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
if( ( IsVirtual(pTab)
&& sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
|| ( (pTab->tabFlags & TF_Readonly)!=0
&& (pParse->db->flags & (SQLITE_WriteSchema|SQLITE_Defensive))==0
&& pParse->nested==0 )
&& sqlite3WritableSchema(pParse->db)==0
&& pParse->nested==0)
){
sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
return 1;

View File

@ -4204,6 +4204,7 @@ Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int);
Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
Expr *sqlite3ExprSkipCollate(Expr*);
int sqlite3CheckCollSeq(Parse *, CollSeq *);
int sqlite3WritableSchema(sqlite3*);
int sqlite3CheckObjectName(Parse *, const char *);
void sqlite3VdbeSetChanges(sqlite3 *, int);
int sqlite3AddInt64(i64*,i64);

View File

@ -7556,6 +7556,7 @@ static int SQLITE_TCLAPI test_sqlite3_db_config(
{ "QPSG", SQLITE_DBCONFIG_ENABLE_QPSG },
{ "TRIGGER_EQP", SQLITE_DBCONFIG_TRIGGER_EQP },
{ "RESET_DB", SQLITE_DBCONFIG_RESET_DATABASE },
{ "DEFENSIVE", SQLITE_DBCONFIG_DEFENSIVE },
};
int i;
int v;

View File

@ -625,6 +625,13 @@ do_test index-18.1 {
CREATE TABLE sqlite_t1(a, b, c);
}
} {1 {object name reserved for internal use: sqlite_t1}}
do_test index-18.1.2 {
sqlite3_db_config db DEFENSIVE 1
catchsql {
CREATE TABLE sqlite_t1(a, b, c);
}
} {1 {object name reserved for internal use: sqlite_t1}}
sqlite3_db_config db DEFENSIVE 0
do_test index-18.2 {
catchsql {
CREATE INDEX sqlite_i1 ON t7(c);