sqlite/0011-Remove_the_SQLITE_OMIT_BTREECOUNT_option.patch
Markeryang b5718f9b04 Fix CVE-2020-13871
Fix CVE-2020-13871
2020-08-04 15:03:24 +08:00

169 lines
5.6 KiB
Diff

From e50478d7279b72a9df4836729c9974abfbce08ff Mon Sep 17 00:00:00 2001
From: drh <drh@noemail.net>
Date: Tue, 17 Mar 2020 13:41:51 +0000
Subject: [PATCH] Remove the SQLITE_OMIT_BTREECOUNT option. Btree count is
required.
patch reference:
https://www.sqlite.org/src/info/a9bfa47aeea27e91
---
src/analyze.c | 14 ++++++++------
src/btree.c | 2 --
src/btree.h | 2 --
src/ctime.c | 3 ---
src/pragma.c | 2 --
src/select.c | 7 ++-----
src/vdbe.c | 2 --
7 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/src/analyze.c b/src/analyze.c
index 11ac430..fa01925 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -408,7 +408,8 @@ static void statInit(
int n; /* Bytes of space to allocate */
sqlite3 *db; /* Database connection */
#ifdef SQLITE_ENABLE_STAT4
- int mxSample = sqlite3_value_int(argv[2]) ? SQLITE_STAT4_SAMPLES : 0;
+ /* Maximum number of samples. 0 if STAT4 data is not collected */
+ int mxSample = sqlite3_value_int64(argv[2]) ? SQLITE_STAT4_SAMPLES : 0;
#endif
/* Decode the three function arguments */
@@ -423,13 +424,14 @@ static void statInit(
/* Allocate the space required for the StatAccum object */
n = sizeof(*p)
+ sizeof(tRowcnt)*nColUp /* StatAccum.anEq */
- + sizeof(tRowcnt)*nColUp /* StatAccum.anDLt */
+ + sizeof(tRowcnt)*nColUp; /* StatAccum.anDLt */
#ifdef SQLITE_ENABLE_STAT4
- + sizeof(tRowcnt)*nColUp /* StatAccum.anLt */
- + sizeof(StatSample)*(nCol+mxSample) /* StatAccum.aBest[], a[] */
- + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample)
+ if( mxSample ){
+ n += sizeof(tRowcnt)*nColUp /* StatAccum.anLt */
+ + sizeof(StatSample)*(nCol+mxSample) /* StatAccum.aBest[], a[] */
+ + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample);
+ }
#endif
- ;
db = sqlite3_context_db_handle(context);
p = sqlite3DbMallocZero(db, n);
if( p==0 ){
diff --git a/src/btree.c b/src/btree.c
index be5d639..78a99d2 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9514,7 +9514,6 @@ int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){
return rc;
}
-#ifndef SQLITE_OMIT_BTREECOUNT
/*
** The first argument, pCur, is a cursor opened on some b-tree. Count the
** number of entries in the b-tree and write the result to *pnEntry.
@@ -9587,7 +9586,6 @@ int sqlite3BtreeCount(sqlite3 *db, BtCursor *pCur, i64 *pnEntry){
/* An error has occurred. Return an error code. */
return rc;
}
-#endif
/*
** Return the pager associated with a BTree. This routine is used for
diff --git a/src/btree.h b/src/btree.h
index 4bd41f7..2085c07 100644
--- a/src/btree.h
+++ b/src/btree.h
@@ -336,9 +336,7 @@ int sqlite3BtreeCursorIsValid(BtCursor*);
#endif
int sqlite3BtreeCursorIsValidNN(BtCursor*);
-#ifndef SQLITE_OMIT_BTREECOUNT
int sqlite3BtreeCount(sqlite3*, BtCursor*, i64*);
-#endif
#ifdef SQLITE_TEST
int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
diff --git a/src/ctime.c b/src/ctime.c
index 013a0c2..aeaaa4f 100644
--- a/src/ctime.c
+++ b/src/ctime.c
@@ -514,9 +514,6 @@ static const char * const sqlite3azCompileOpt[] = {
#if SQLITE_OMIT_BLOB_LITERAL
"OMIT_BLOB_LITERAL",
#endif
-#if SQLITE_OMIT_BTREECOUNT
- "OMIT_BTREECOUNT",
-#endif
#if SQLITE_OMIT_CAST
"OMIT_CAST",
#endif
diff --git a/src/pragma.c b/src/pragma.c
index 4d33e8c..0de9dc3 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -1729,7 +1729,6 @@ void sqlite3Pragma(
}
sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
sqlite3VdbeJumpHere(v, loopTop-1);
-#ifndef SQLITE_OMIT_BTREECOUNT
if( !isQuick ){
sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
@@ -1743,7 +1742,6 @@ void sqlite3Pragma(
sqlite3VdbeJumpHere(v, addr);
}
}
-#endif /* SQLITE_OMIT_BTREECOUNT */
}
}
{
diff --git a/src/select.c b/src/select.c
index f61fbce..0cc6b87 100644
--- a/src/select.c
+++ b/src/select.c
@@ -6620,7 +6620,6 @@ int sqlite3Select(
} /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
else {
-#ifndef SQLITE_OMIT_BTREECOUNT
Table *pTab;
if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){
/* If isSimpleCount() returns a pointer to a Table structure, then
@@ -6678,10 +6677,8 @@ int sqlite3Select(
sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
sqlite3VdbeAddOp1(v, OP_Close, iCsr);
explainSimpleCount(pParse, pTab, pBest);
- }else
-#endif /* SQLITE_OMIT_BTREECOUNT */
- {
- int regAcc = 0; /* "populate accumulators" flag */
+ }else{
+ int regAcc = 0; /* "populate accumulators" flag */
/* If there are accumulator registers but no min() or max() functions
** without FILTER clauses, allocate register regAcc. Register regAcc
diff --git a/src/vdbe.c b/src/vdbe.c
index b9d2d12..acb4a14 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -3194,7 +3194,6 @@ case OP_MakeRecord: {
** Store the number of entries (an integer value) in the table or index
** opened by cursor P1 in register P2
*/
-#ifndef SQLITE_OMIT_BTREECOUNT
case OP_Count: { /* out2 */
i64 nEntry;
BtCursor *pCrsr;
@@ -3209,7 +3208,6 @@ case OP_Count: { /* out2 */
pOut->u.i = nEntry;
goto check_for_interrupt;
}
-#endif
/* Opcode: Savepoint P1 * * P4 *
**
--
2.23.0