aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2015-11-07 18:07:15 +0000
committerdan <dan@noemail.net>2015-11-07 18:07:15 +0000
commitcc033054734028fa582afe17521afce3da433df5 (patch)
tree1c92d9e981db7cb3ef9a659a8c0d5021e4630368 /src/select.c
parentd6b7946c32ec1cf4b77f51ab82db553cf466c488 (diff)
parentfe88fbfc828594d00999649ab6a8dcff5db64821 (diff)
downloadsqlite-cc033054734028fa582afe17521afce3da433df5.tar.gz
sqlite-cc033054734028fa582afe17521afce3da433df5.zip
Fix a bug in CTE handling discovered by LibFuzzer that can cause an infinite loop in the query planner.
FossilOrigin-Name: 088009efdd56160bb4eee0fbd829a529b141274e
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/select.c b/src/select.c
index 8db983891..bd732e5bc 100644
--- a/src/select.c
+++ b/src/select.c
@@ -3972,7 +3972,7 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
** object that the returned CTE belongs to.
*/
static struct Cte *searchWith(
- With *pWith, /* Current outermost WITH clause */
+ With *pWith, /* Current innermost WITH clause */
struct SrcList_item *pItem, /* FROM clause element to resolve */
With **ppContext /* OUT: WITH clause return value belongs to */
){
@@ -4003,11 +4003,12 @@ static struct Cte *searchWith(
** statement with which it is associated.
*/
void sqlite3WithPush(Parse *pParse, With *pWith, u8 bFree){
- assert( bFree==0 || pParse->pWith==0 );
+ assert( bFree==0 || (pParse->pWith==0 && pParse->pWithToFree==0) );
if( pWith ){
+ assert( pParse->pWith!=pWith );
pWith->pOuter = pParse->pWith;
pParse->pWith = pWith;
- pParse->bFreeWith = bFree;
+ if( bFree ) pParse->pWithToFree = pWith;
}
}
@@ -4100,6 +4101,7 @@ static int withExpand(
pSavedWith = pParse->pWith;
pParse->pWith = pWith;
sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
+ pParse->pWith = pWith;
for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
pEList = pLeft->pEList;