Ensure that variables are not used in the WINDOW clause of a query inside

of a trigger.  dbsqlfuzz d9cf66100064952b66951845dfab41de1c124611

FossilOrigin-Name: 1a341378ab24a5091e6cf03b9e957d11b2bfe5c711835e8c583785f8fa0125d3
This commit is contained in:
drh 2021-04-17 13:46:23 +00:00
parent 1929cc0d8a
commit 7b0d34fe32
6 changed files with 32 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Add\sgeopoly\sto\s$::sqlite_options()\sand\suse\sit\sto\spass\smore\stests.
D 2021-04-16T23:43:22.674
C Ensure\sthat\svariables\sare\snot\sused\sin\sthe\sWINDOW\sclause\sof\sa\squery\sinside\nof\sa\strigger.\s\sdbsqlfuzz\sd9cf66100064952b66951845dfab41de1c124611
D 2021-04-17T13:46:23.808
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -478,7 +478,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
F src/alter.c 14d5d9ba332de515c6e2f729e728426cdd6f5683cdc356ba6b6e3444e1ed210e
F src/analyze.c 01c6c6765cb4d40b473b71d85535093730770bb186f2f473abac25f07fcdee5c
F src/attach.c 9cbe761e464025694df8e6f6ee4d9f41432c3a255ca9443ccbb4130eeb87cf72
F src/attach.c f4c5352b7e65760bed220e46176b540d43fdb2d9453a262c5fa467e5a8dfaa61
F src/auth.c 08954fdc4cc2da5264ba5b75cfd90b67a6fc7d1710a02ccf917c38eadec77853
F src/backup.c 3014889fa06e20e6adfa0d07b60097eec1f6e5b06671625f476a714d2356513d
F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
@ -547,7 +547,7 @@ F src/shell.c.in 9320b476fde0f7c46700e5695b69b435f1e46843a1513cdd187ac426cdbee01
F src/sqlite.h.in 18ec33e32001721fd4e9c4705a24a85dff04956ac2c0a21775058884ba845b09
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 61b38c073d5e1e96a3d45271b257aef27d0d13da2bea5347692ae579475cd95e
F src/sqliteInt.h 95679aa6addc29e48453770a80aeb8ea623d3fa76e309768d83a00ad87fe9111
F src/sqliteInt.h 73abdd2a633ccff6e4b5d44994d68a25b8009eca6a94d2d582404e74114071af
F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
F src/status.c 4b8bc2a6905163a38b739854a35b826c737333fab5b1f8e03fa7eb9a4799c4c1
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@ -628,7 +628,7 @@ F src/vtab.c 032a0165c147fda16927e6a3230e90c068d4af93f887ce94e26f678fe48e5e4c
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c 69e770e96fd56cc21608992bf2c6f1f3dc5cf2572d0495c6a643b06c3a679f14
F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
F src/walker.c d42d6c80ea363ef689a462e65eefcfe87deab924c50de5baa37ecb6af7d7ddaa
F src/walker.c df4f432b10011cd587b16afa861ae8878ef1b872dd042565efa4db346bbdc793
F src/where.c 1c305bab0996a63219a6cb3d4718587f3a5dc5608120c4448985aa2bef88b7f5
F src/whereInt.h 446e5e8018f83358ef917cf32d8e6a86dc8430113d0b17e720f1839d3faa44c4
F src/wherecode.c 0e42f4ad53962e90349462520891734ed3217c7852f41c69ffac7a9eeaf31451
@ -1769,7 +1769,7 @@ F test/win32heap.test 10fd891266bd00af68671e702317726375e5407561d859be1aa04696f2
F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972
F test/win32longpath.test 4baffc3acb2e5188a5e3a895b2b543ed09e62f7c72d713c1feebf76222fe9976
F test/win32nolock.test ac4f08811a562e45a5755e661f45ca85892bdbbc
F test/window1.test d85fd6d82f06ac98da31a7ca1417a051de0a7c01a8c61e4e93d3c7383544f5c7
F test/window1.test 515512f47c654e1b19e9708aa53d269dfe7acafd3c458e1dfdda783ac8822150
F test/window2.tcl 492c125fa550cda1dd3555768a2303b3effbeceee215293adf8871efc25f1476
F test/window2.test e466a88bd626d66edc3d352d7d7e1d5531e0079b549ba44efb029d1fbff9fd3c
F test/window3.tcl acea6e86a4324a210fd608d06741010ca83ded9fde438341cb978c49928faf03
@ -1912,7 +1912,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 ab83a99899ceae931b43e0c4b3f8f8b83bc832f1568de5692c0d038c968f8a87
R a25a23255eb14ac26c02b1d56b4537bc
U larrybr
Z 0a0ab19ca8aa12c6c640b6bd1ffda819
P 23da5016b66f3947cc902dbe2766ea9f5a00f85312a652b536ab51d657446ab7
R bf25a23f30169f2cf2c12eb36cf30778
U drh
Z de881fd9f1b18391bcbd6c6b28a4ca60

View File

@ -1 +1 @@
23da5016b66f3947cc902dbe2766ea9f5a00f85312a652b536ab51d657446ab7
1a341378ab24a5091e6cf03b9e957d11b2bfe5c711835e8c583785f8fa0125d3

View File

@ -514,6 +514,7 @@ void sqlite3FixInit(
pFix->w.xSelectCallback2 = 0;
pFix->w.walkerDepth = 0;
pFix->w.eCode = 0;
pFix->w.bWalkWinDefn = 1;
pFix->w.u.pFix = pFix;
}

View File

@ -3833,6 +3833,7 @@ struct Walker {
void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
int walkerDepth; /* Number of subqueries */
u16 eCode; /* A small processing code */
unsigned bWalkWinDefn : 1; /* True to walk pWinDefn */
union { /* Extra data for callback */
NameContext *pNC; /* Naming context */
int n; /* A counter */

View File

@ -130,10 +130,12 @@ int sqlite3WalkSelectExpr(Walker *pWalker, Select *p){
if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
#if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE)
{
Parse *pParse = pWalker->pParse;
if( pParse && IN_RENAME_OBJECT ){
#if !defined(SQLITE_OMIT_WINDOWFUNC)
if( p->pWinDefn ){
Parse *pParse;
if( pWalker->bWalkWinDefn
|| ((pParse = pWalker->pParse)!=0 && IN_RENAME_OBJECT)
){
/* The following may return WRC_Abort if there are unresolvable
** symbols (e.g. a table that does not exist) in a window definition. */
int rc = walkWindowList(pWalker, p->pWinDefn, 0);

View File

@ -374,6 +374,19 @@ do_execsql_test 9.3 {
SELECT *, min(z) OVER (ORDER BY x) FROM aaa ORDER BY 1;
} {1 g g g 2 i i g 3 l l g 4 g l g 5 a l g 6 m m g}
do_catchsql_test 9.4 {
-- 2021-04-17 dbsqlfuzz d9cf66100064952b66951845dfab41de1c124611
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a,b,c,d);
DROP TABLE IF EXISTS t2;
CREATE TABLE t2(x,y);
CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
INSERT INTO t2(x,y)
SELECT a, max(d) OVER w1 FROM t1
WINDOW w1 AS (PARTITION BY EXISTS(SELECT 1 FROM t1 WHERE c=?1) );
END;
} {1 {trigger cannot use variables}}
#-------------------------------------------------------------------------
#
do_execsql_test 10.0 {