diff options
author | drh <> | 2021-10-07 12:11:20 +0000 |
---|---|---|
committer | drh <> | 2021-10-07 12:11:20 +0000 |
commit | 78b2fa8610bd2d149af7746faa79f095e505550c (patch) | |
tree | 2cc1a3e64483ca30acb31ead81e32df29913387f /src/alter.c | |
parent | 16a8f28e492507523c6b0b9d0bc0d9fd43c253a7 (diff) | |
download | sqlite-78b2fa8610bd2d149af7746faa79f095e505550c.tar.gz sqlite-78b2fa8610bd2d149af7746faa79f095e505550c.zip |
Protect every access to the Table.u union using a nearby assert() or branch.
FossilOrigin-Name: 50e08338aed7ac0cee600098d2ecd4b3b7bfd31a597bb26773badf3d2e2582c8
Diffstat (limited to 'src/alter.c')
-rw-r--r-- | src/alter.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/alter.c b/src/alter.c index 81f6cf69d..8b8fbf2be 100644 --- a/src/alter.c +++ b/src/alter.c @@ -367,6 +367,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ if( pDflt && pDflt->pLeft->op==TK_NULL ){ pDflt = 0; } + assert( IsOrdinaryTable(pNew) ); if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){ sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "Cannot add a REFERENCES column with non-NULL default value"); @@ -409,7 +410,8 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ } /* substr() operations on characters, but addColOffset is in bytes. So we ** have to use printf() to translate between these units: */ - assert( !IsVirtual(pTab) ); + assert( IsOrdinaryTable(pTab) ); + assert( IsOrdinaryTable(pNew) ); sqlite3NestedParse(pParse, "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = printf('%%.%ds, ',sql) || %Q" @@ -503,6 +505,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ } sqlite3MayAbort(pParse); + assert( IsOrdinaryTable(pTab) ); assert( pTab->u.tab.addColOffset>0 ); iDb = sqlite3SchemaToIndex(db, pTab->pSchema); @@ -533,7 +536,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName); pCol->hName = sqlite3StrIHash(pCol->zCnName); } - assert( !IsVirtual(pNew) ); + assert( IsOrdinaryTable(pNew) ); pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0); pNew->pSchema = db->aDb[iDb].pSchema; pNew->u.tab.addColOffset = pTab->u.tab.addColOffset; @@ -1531,7 +1534,7 @@ static void renameColumnFunc( #endif } - assert( !IsVirtual(sParse.pNewTable) ); + assert( IsOrdinaryTable(sParse.pNewTable) ); for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ for(i=0; i<pFKey->nCol; i++){ if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){ @@ -1721,7 +1724,7 @@ static void renameTableFunc( && !IsVirtual(pTab) ){ FKey *pFKey; - assert( !IsVirtual(pTab) ); + assert( IsOrdinaryTable(pTab) ); for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); @@ -2042,7 +2045,7 @@ static void dropColumnFunc( pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName); zEnd = (const char*)pEnd->t.z; }else{ - assert( !IsVirtual(pTab) ); + assert( IsOrdinaryTable(pTab) ); zEnd = (const char*)&zSql[pTab->u.tab.addColOffset]; while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--; } |