aboutsummaryrefslogtreecommitdiff
path: root/src/build.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2020-03-10 19:24:38 +0000
committerdrh <drh@noemail.net>2020-03-10 19:24:38 +0000
commite7375bfa727bfa12649897fd6a655f81b703f0db (patch)
treeceb8af56043e8a55900b807487cf3cbc0799e4cf /src/build.c
parent5cf1b611a20201aa141b258901cbfc2950e2037e (diff)
downloadsqlite-e7375bfa727bfa12649897fd6a655f81b703f0db.tar.gz
sqlite-e7375bfa727bfa12649897fd6a655f81b703f0db.zip
Enhanced detection logic for preventing the use of static schema expressions
by code generating routines. FossilOrigin-Name: 5f60b527b938c0778e8f725c635ce0dc5ed7a4e01fd6252aa2cdb64da2f625bc
Diffstat (limited to 'src/build.c')
-rw-r--r--src/build.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/build.c b/src/build.c
index a7dc36ff5..73e4cea7c 100644
--- a/src/build.c
+++ b/src/build.c
@@ -2157,6 +2157,32 @@ int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
}
#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
+#ifdef SQLITE_DEBUG
+/*
+** Mark all nodes of an expression as EP_Immutable, indicating that
+** they should not be changed. Expressions attached to a table or
+** index definition are tagged this way to help ensure that we do
+** not pass them into code generator routines by mistake.
+*/
+static int markImmutableExprStep(Walker *pWalker, Expr *pExpr){
+ ExprSetVVAProperty(pExpr, EP_Immutable);
+ return WRC_Continue;
+}
+static void markExprListImmutable(ExprList *pList){
+ if( pList ){
+ Walker w;
+ memset(&w, 0, sizeof(w));
+ w.xExprCallback = markImmutableExprStep;
+ w.xSelectCallback = sqlite3SelectWalkNoop;
+ w.xSelectCallback2 = 0;
+ sqlite3WalkExprList(&w, pList);
+ }
+}
+#else
+#define markExprListImmutable(X) /* no-op */
+#endif /* SQLITE_DEBUG */
+
+
/*
** This routine is called to report the final ")" that terminates
** a CREATE TABLE statement.
@@ -2249,6 +2275,8 @@ void sqlite3EndTable(
** actually be used if PRAGMA writable_schema=ON is set. */
sqlite3ExprListDelete(db, p->pCheck);
p->pCheck = 0;
+ }else{
+ markExprListImmutable(p->pCheck);
}
}
#endif /* !defined(SQLITE_OMIT_CHECK) */