Add the SQLITE_LIMIT_TRIGGER_DEPTH option to sqlite3_limit().

FossilOrigin-Name: d7dc8b433691745b3842282569f1573d1e057963
This commit is contained in:
drh 2009-09-07 18:14:02 +00:00
parent 2f8e4959d1
commit 417168ade2
10 changed files with 127 additions and 32 deletions

View File

@ -1,5 +1,8 @@
C Merge\s[/src/vinfo/1958db4493461b3a54217a6a45f2730287107860|1958db4493]\sand\s[/src/vinfo/26cd015c0ee1c18dd37f11b47ce35cfa320b3514|26cd015c0e].
D 2009-09-07T17:41:48
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Add\sthe\sSQLITE_LIMIT_TRIGGER_DEPTH\soption\sto\ssqlite3_limit().
D 2009-09-07T18:14:02
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 73ddeec9dd10b85876c5c2ce1fdce627e1dcc7f8
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -126,7 +129,7 @@ F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0
F src/legacy.c 303b4ffcf1ae652fcf5ef635846c563c254564f6
F src/lempar.c 0c4d1ab0a5ef2b0381eb81a732c54f68f27a574d
F src/loadext.c 0e88a335665db0b2fb4cece3e49dcb65d832635a
F src/main.c 6688d56c2437eed4a8bbbb2fd517c59ff927f337
F src/main.c e33c4d17cc0a398847f5c9926ccdfe7e66605b87
F src/malloc.c b1725183bcc4ce2e569f1b65da844dc3e4c7a643
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
@ -159,16 +162,16 @@ F src/printf.c 508a1c59433353552b6553cba175eaa7331f8fc1
F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
F src/resolve.c 941843301f6fda6c6350839c6955a172441a0782
F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f
F src/select.c 8bc7347fe88cf16ac2cb1a37fb918d1417ab4142
F src/select.c 95809555bf3614d0043d635c85948520fe21e741
F src/shell.c db2643650b9268df89a4bedca3f1c6d9e786f1bb
F src/sqlite.h.in 94052f827890de6fb7c913b95507076909261d9b
F src/sqlite.h.in e5949b46f9a05aadde22848f92fae5c9ba87ee0e
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
F src/sqliteInt.h 0abbf6e260e19e41f1d57dbf02b1283f77cce81a
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
F src/sqliteInt.h 13bb8c9abbdfe33c1fe685921b4a36e484a3d108
F src/sqliteLimit.h be44f7f46c14bb4c21870074b1e6f1ac0abd6701
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c cc86ad3d6ad54df7c63a3e807b5783c90411a08d
F src/tclsqlite.c 5eea5025c370d3a91ce0415f9d46f96fdc7aef44
F src/test1.c eacb3456a9419191f42a0f601e12ca8a424a6de1
F src/test1.c 83a685fa2c96f005934ed09146b53522b1aa533e
F src/test2.c 0de743ec8890ca4f09e0bce5d6d5a681f5957fec
F src/test3.c 2445c2beb5e7a0c91fd8136dc1339ec369a24898
F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
@ -205,7 +208,7 @@ F src/update.c 3e97974baa914f32d4ae690fa0cb7281aff8cd39
F src/utf.c 99cf927eabb104621ba889ac0dd075fc1657ad30
F src/util.c 59d4e9456bf1fe581f415a783fa0cee6115c8f35
F src/vacuum.c 3fe0eebea6d2311c1c2ab2962887d11f7a4dcfb0
F src/vdbe.c a158f0f3efbf2a66037dbfe4024398719cf61596
F src/vdbe.c 4e3c6895475cf8a9930cb39f7e9855acb7019349
F src/vdbe.h 080fe6bc1264438becb8bf9b9f3c84074c336b78
F src/vdbeInt.h 6094e60f64d7a9d4352d4e6b90d1219dce947ad9
F src/vdbeapi.c 8d5013ab6104be757c208a70ffb191cc27d2b688
@ -682,7 +685,7 @@ F test/trigger8.test 30cb0530bd7c4728055420e3f739aa00412eafa4
F test/trigger9.test 5b0789f1c5c4600961f8e68511b825b87be53e31
F test/triggerA.test 0718ad2d9bfef27c7af00e636df79bee6b988da7
F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe
F test/triggerC.test 6ee1611c7ebd8ac892e67bd0e6e2ef7d9229dbc8
F test/triggerC.test cc43b4a62f447a0b0ec76ce511758c460c049c83
F test/types.test 9a825ec8eea4e965d7113b74c76a78bb5240f2ac
F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
F test/types3.test a0f66bf12f80fad89493535474f7a6d16fa58150
@ -750,7 +753,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 1958db4493461b3a54217a6a45f2730287107860 26cd015c0ee1c18dd37f11b47ce35cfa320b3514
R c696e4c21d675d7ca4562a71667fb0c3
U dan
Z 7455be8358f8e7bf1ced5a136a1693ca
P ecbe0832be77599c7cc66fb9968d0f419000d231
R d34c486626a8ce5a53145ee9d825c061
U drh
Z c32d324c29421eb9787794c39572ee17
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFKpU1toxKgR168RlERAiq6AJ9XuXc0u1hWnpGpmA/epzDAzopjbQCeJgNH
Khw73UH7YVrOiFFOVF+gTAk=
=8PSG
-----END PGP SIGNATURE-----

View File

@ -1 +1 @@
ecbe0832be77599c7cc66fb9968d0f419000d231
d7dc8b433691745b3842282569f1573d1e057963

View File

@ -1448,6 +1448,7 @@ static const int aHardLimit[] = {
SQLITE_MAX_ATTACHED,
SQLITE_MAX_LIKE_PATTERN_LENGTH,
SQLITE_MAX_VARIABLE_NUMBER,
SQLITE_MAX_TRIGGER_DEPTH,
};
/*
@ -1483,6 +1484,9 @@ static const int aHardLimit[] = {
#if SQLITE_MAX_COLUMN>32767
# error SQLITE_MAX_COLUMN must not exceed 32767
#endif
#if SQLITE_MAX_TRIGGER_DEPTH<1
# error SQLITE_MAX_TRIGGER_DEPTH must be at least 1
#endif
/*

View File

@ -881,7 +881,7 @@ static const char *columnType(
int iCol = pExpr->iColumn; /* Index of column in pTab */
testcase( pExpr->op==TK_AGG_COLUMN );
testcase( pExpr->op==TK_COLUMN );
while( pNC && !pTab ){
while( ALWAYS(pNC) && !pTab ){
SrcList *pTabList = pNC->pSrcList;
for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
if( j<pTabList->nSrc ){
@ -892,16 +892,12 @@ static const char *columnType(
}
}
if( pTab==0 ){
/* FIX ME:
** This can occurs if you have something like "SELECT new.x;" inside
** a trigger. In other words, if you reference the special "new"
** table in the result set of a select. We do not have a good way
** to find the actual table type, so call it "TEXT". This is really
** something of a bug, but I do not know how to fix it.
**
** This code does not produce the correct answer - it just prevents
** a segfault. See ticket #1229.
if( NEVER(pTab==0) ){
/* At one time, code such as "SELECT new.x" within a trigger would
** cause this condition to run. Since then, we have restructured how
** trigger code is generated and so this condition is no longer
** possible. But it seems prudent to keep the test in place in
** case something else changes.
*/
zType = "TEXT";
break;

View File

@ -2317,6 +2317,9 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
** <dd>The maximum number of variables in an SQL statement that can
** be bound.</dd>
**
** <dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
** <dd>The maximum depth of recursion for triggers.</dd>
** </dl>
*/
#define SQLITE_LIMIT_LENGTH 0
@ -2329,6 +2332,7 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
#define SQLITE_LIMIT_ATTACHED 7
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
/*
** CAPI3REF: Compiling An SQL Statement {H13010} <S10000>

View File

@ -707,7 +707,7 @@ struct Schema {
** The number of different kinds of things that can be limited
** using the sqlite3_limit() interface.
*/
#define SQLITE_N_LIMIT (SQLITE_LIMIT_VARIABLE_NUMBER+1)
#define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_DEPTH+1)
/*
** Lookaside malloc is a set of fixed-size buffers that can be used

View File

@ -188,3 +188,10 @@
#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
#endif
/*
** Maximum depth of recursion for triggers.
*/
#ifndef SQLITE_MAX_TRIGGER_DEPTH
# define SQLITE_MAX_TRIGGER_DEPTH 1000
#endif

View File

@ -4721,10 +4721,11 @@ static int test_limit(
{ "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED },
{ "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
{ "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER },
{ "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH },
/* Out of range test cases */
{ "SQLITE_LIMIT_TOOSMALL", -1, },
{ "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_VARIABLE_NUMBER+1 },
{ "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_TRIGGER_DEPTH+1 },
};
int i, id;
int val;

View File

@ -4802,8 +4802,7 @@ case OP_Program: { /* jump */
if( pFrame ) break;
}
/* TODO: This constant should be configurable. */
if( p->nFrame>1000 ){
if( p->nFrame>db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
rc = SQLITE_ERROR;
sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
break;

View File

@ -266,6 +266,82 @@ do_test triggerC-3.1.3 {
execsql { SELECT * FROM t3 }
} {}
do_test triggerC-3.2.1 {
execsql {
CREATE TABLE t3b(x);
CREATE TRIGGER t3bi AFTER INSERT ON t3b WHEN new.x<2000 BEGIN
INSERT INTO t3b VALUES(new.x+1);
END;
}
catchsql {
INSERT INTO t3b VALUES(1);
}
} {1 {too many levels of trigger recursion}}
do_test triggerC-3.2.2 {
db eval {SELECT * FROM t3b}
} {}
do_test triggerC-3.3.1 {
catchsql {
INSERT INTO t3b VALUES(1000);
}
} {0 {}}
do_test triggerC-3.3.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {1001 2000 1000}
do_test triggerC-3.4.1 {
catchsql {
DELETE FROM t3b;
INSERT INTO t3b VALUES(999);
}
} {1 {too many levels of trigger recursion}}
do_test triggerC-3.4.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {0 {} {}}
do_test triggerC-3.5.1 {
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 100
catchsql {
INSERT INTO t3b VALUES(1900);
}
} {0 {}}
do_test triggerC-3.5.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {101 2000 1900}
do_test triggerC-3.5.3 {
catchsql {
DELETE FROM t3b;
INSERT INTO t3b VALUES(1899);
}
} {1 {too many levels of trigger recursion}}
do_test triggerC-3.5.4 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {0 {} {}}
do_test triggerC-3.6.1 {
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1
catchsql {
INSERT INTO t3b VALUES(1999);
}
} {0 {}}
do_test triggerC-3.6.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {2 2000 1999}
do_test triggerC-3.6.3 {
catchsql {
DELETE FROM t3b;
INSERT INTO t3b VALUES(1998);
}
} {1 {too many levels of trigger recursion}}
do_test triggerC-3.6.4 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {0 {} {}}
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000
#-----------------------------------------------------------------------
# This next block of tests, triggerC-4.*, checks that affinity
# transformations and constraint processing is performed at the correct
@ -456,5 +532,3 @@ foreach {n insert log} {
}
finish_test