1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Fix out-of-bounds array references in the "echo" virtual table module

used for testing.  No changes to the SQLite core.

FossilOrigin-Name: 7b449b301ea03295262b8d572b02625e4b39cfa5
This commit is contained in:
drh
2012-03-20 03:10:51 +00:00
parent 0299b40f0f
commit 82ebc2a098
3 changed files with 13 additions and 17 deletions

View File

@@ -831,13 +831,10 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
if( !isIgnoreUsable && !pConstraint->usable ) continue;
iCol = pConstraint->iColumn;
if( pVtab->aIndex[iCol] || iCol<0 ){
char *zCol = pVtab->aCol[iCol];
if( iCol<0 || pVtab->aIndex[iCol] ){
char *zCol = iCol>=0 ? pVtab->aCol[iCol] : "rowid";
char *zOp = 0;
useIdx = 1;
if( iCol<0 ){
zCol = "rowid";
}
switch( pConstraint->op ){
case SQLITE_INDEX_CONSTRAINT_EQ:
zOp = "="; break;
@@ -870,13 +867,12 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
** on a column that this virtual table has an index for, then consume
** the ORDER BY clause.
*/
if( pIdxInfo->nOrderBy==1 && pVtab->aIndex[pIdxInfo->aOrderBy->iColumn] ){
if( pIdxInfo->nOrderBy==1 && (
pIdxInfo->aOrderBy->iColumn<0 ||
pVtab->aIndex[pIdxInfo->aOrderBy->iColumn]) ){
int iCol = pIdxInfo->aOrderBy->iColumn;
char *zCol = pVtab->aCol[iCol];
char *zCol = iCol>=0 ? pVtab->aCol[iCol] : "rowid";
char *zDir = pIdxInfo->aOrderBy->desc?"DESC":"ASC";
if( iCol<0 ){
zCol = "rowid";
}
zNew = sqlite3_mprintf(" ORDER BY %s %s", zCol, zDir);
string_concat(&zQuery, zNew, 1, &rc);
pIdxInfo->orderByConsumed = 1;