diff options
author | drh <drh@noemail.net> | 2019-11-16 12:04:38 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-11-16 12:04:38 +0000 |
commit | d0c51d1a041966bccc598d114aa17a13cf64d662 (patch) | |
tree | 5cf626971768c09f2866e69458ffc74fc0486435 /src | |
parent | 47bcc34271435e376b57a8482e06803f4a7a6c4f (diff) | |
download | sqlite-d0c51d1a041966bccc598d114aa17a13cf64d662.tar.gz sqlite-d0c51d1a041966bccc598d114aa17a13cf64d662.zip |
Do not allow shadow tables to be dropped in defensive mode.
FossilOrigin-Name: 70390bbca49e706649ca5b7c031f0baf416fc38798c17e5f3b73746b3e66e3b5
Diffstat (limited to 'src')
-rw-r--r-- | src/build.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/build.c b/src/build.c index ecec4a374..2cc00d9d8 100644 --- a/src/build.c +++ b/src/build.c @@ -2895,6 +2895,22 @@ void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){ } /* +** Return true if it is not allowed to drop the given table +*/ +static int tableMayNotBeDropped(Parse *pParse, Table *pTab){ + if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ + if( sqlite3StrNICmp(pTab->zName+7, "stat", 4)==0 ) return 0; + if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0; + return 1; + } + if( pTab->tabFlags & TF_Shadow ){ + sqlite3 *db = pParse->db; + if( (db->flags & SQLITE_Defensive)!=0 && db->nVdbeExec==0 ) return 1; + } + return 0; +} + +/* ** This routine is called to do the work of a DROP TABLE statement. ** pName is the name of the table to be dropped. */ @@ -2963,9 +2979,7 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr){ } } #endif - if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 - && sqlite3StrNICmp(pTab->zName+7, "stat", 4)!=0 - && sqlite3StrNICmp(pTab->zName+7, "parameters", 10)!=0 ){ + if( tableMayNotBeDropped(pParse, pTab) ){ sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName); goto exit_drop_table; } |