aboutsummaryrefslogtreecommitdiff
path: root/src/wherecode.c
diff options
context:
space:
mode:
authordrh <>2021-10-07 17:43:30 +0000
committerdrh <>2021-10-07 17:43:30 +0000
commita4eeccdfdf9a9b4a5a007d17ac51f124656272d9 (patch)
tree88ceffcbf0266114987be591131990addc08ca46 /src/wherecode.c
parent9d43db5b5c82a4242b97cd85c8950c3fcd1d6961 (diff)
downloadsqlite-a4eeccdfdf9a9b4a5a007d17ac51f124656272d9.tar.gz
sqlite-a4eeccdfdf9a9b4a5a007d17ac51f124656272d9.zip
Protect all accesses to the Expr.x union using nearby assert()s and branches.
FossilOrigin-Name: 8eaa1d4a98b24adf245bbd2fe9212aa6a924a0f09c445906d7f87574f36a7423
Diffstat (limited to 'src/wherecode.c')
-rw-r--r--src/wherecode.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/wherecode.c b/src/wherecode.c
index 15e4aa839..d803c674f 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -416,13 +416,18 @@ static Expr *removeUnindexableInClauseTerms(
Expr *pNew;
pNew = sqlite3ExprDup(db, pX, 0);
if( db->mallocFailed==0 ){
- ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
- ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
+ ExprList *pOrigRhs; /* Original unmodified RHS */
+ ExprList *pOrigLhs; /* Original unmodified LHS */
ExprList *pRhs = 0; /* New RHS after modifications */
ExprList *pLhs = 0; /* New LHS after mods */
int i; /* Loop counter */
Select *pSelect; /* Pointer to the SELECT on the RHS */
+ assert( ExprUseXSelect(pNew) );
+ pOrigRhs = pNew->x.pSelect->pEList;
+ assert( pNew->pLeft!=0 );
+ assert( ExprUseXList(pNew->pLeft) );
+ pOrigLhs = pNew->pLeft->x.pList;
for(i=iEq; i<pLoop->nLTerm; i++){
if( pLoop->aLTerm[i]->pExpr==pX ){
int iField = pLoop->aLTerm[i]->u.x.iField - 1;
@@ -540,7 +545,7 @@ static int codeEqualityTerm(
}
iTab = 0;
- if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
+ if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
}else{
sqlite3 *db = pParse->db;
@@ -1105,7 +1110,7 @@ static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
assert( nReg>0 );
if( p && sqlite3ExprIsVector(p) ){
#ifndef SQLITE_OMIT_SUBQUERY
- if( (p->flags & EP_xIsSelect) ){
+ if( ExprUseXSelect(p) ){
Vdbe *v = pParse->pVdbe;
int iSelect;
assert( p->op==TK_SELECT );
@@ -1115,7 +1120,9 @@ static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
#endif
{
int i;
- ExprList *pList = p->x.pList;
+ const ExprList *pList;
+ assert( ExprUseXList(p) );
+ pList = p->x.pList;
assert( nReg<=pList->nExpr );
for(i=0; i<nReg; i++){
sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i);
@@ -2461,7 +2468,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
if( pAlt==0 ) continue;
if( pAlt->wtFlags & (TERM_CODED) ) continue;
if( (pAlt->eOperator & WO_IN)
- && (pAlt->pExpr->flags & EP_xIsSelect)
+ && ExprUseXSelect(pAlt->pExpr)
&& (pAlt->pExpr->x.pSelect->pEList->nExpr>1)
){
continue;