Blame SOURCES/sqlite-3.26.0-CVE-2019-16168.patch

7d97b9
From ab17169870e985b062e520ecf95e6c79ad784f38 Mon Sep 17 00:00:00 2001
7d97b9
From: Ondrej Dubaj <odubaj@redhat.com>
7d97b9
Date: Thu, 23 Apr 2020 11:25:13 +0200
7d97b9
Subject: [PATCH] fixed CVE-2019-16168 (rhbz#1826897)
7d97b9
7d97b9
---
7d97b9
 src/analyze.c      |  4 +++-
7d97b9
 src/where.c        |  1 +
7d97b9
 test/analyzeC.test | 13 +++++++++++++
7d97b9
 3 files changed, 17 insertions(+), 1 deletion(-)
7d97b9
7d97b9
diff --git a/src/analyze.c b/src/analyze.c
7d97b9
index 5075b57..e47c0f5 100644
7d97b9
--- a/src/analyze.c
7d97b9
+++ b/src/analyze.c
7d97b9
@@ -1497,7 +1497,9 @@ static void decodeIntArray(
7d97b9
       if( sqlite3_strglob("unordered*", z)==0 ){
7d97b9
         pIndex->bUnordered = 1;
7d97b9
       }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
7d97b9
-        pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3));
7d97b9
+        int sz = sqlite3Atoi(z+3);
7d97b9
+        if( sz<2 ) sz = 2;
7d97b9
+        pIndex->szIdxRow = sqlite3LogEst(sz); 
7d97b9
       }else if( sqlite3_strglob("noskipscan*", z)==0 ){
7d97b9
         pIndex->noSkipScan = 1;
7d97b9
       }
7d97b9
diff --git a/src/where.c b/src/where.c
7d97b9
index 8e01660..1a4fa51 100644
7d97b9
--- a/src/where.c
7d97b9
+++ b/src/where.c
7d97b9
@@ -2655,6 +2655,7 @@ static int whereLoopAddBtreeIndex(
7d97b9
     ** it to pNew->rRun, which is currently set to the cost of the index
7d97b9
     ** seek only. Then, if this is a non-covering index, add the cost of
7d97b9
     ** visiting the rows in the main table.  */
7d97b9
+    assert( pSrc->pTab->szTabRow>0 );
7d97b9
     rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
7d97b9
     pNew->rRun = sqlite3LogEstAdd(rLogSize, rCostIdx);
7d97b9
     if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){
7d97b9
diff --git a/test/analyzeC.test b/test/analyzeC.test
7d97b9
index 02faa9c..3595c9d 100644
7d97b9
--- a/test/analyzeC.test
7d97b9
+++ b/test/analyzeC.test
7d97b9
@@ -132,6 +132,19 @@ do_execsql_test 4.3 {
7d97b9
   SELECT count(a) FROM t1;
7d97b9
 } {/.*INDEX t1ca.*/}
7d97b9
 
7d97b9
+# 2019-08-15.
7d97b9
+# Ticket https://www.sqlite.org/src/tktview/e4598ecbdd18bd82945f602901
7d97b9
+# The sz=N parameter in the sqlite_stat1 table needs to have a value of
7d97b9
+# 2 or more to avoid a division by zero in the query planner.
7d97b9
+#
7d97b9
+do_execsql_test 4.4 {
7d97b9
+  DROP TABLE IF EXISTS t44;
7d97b9
+  CREATE TABLE t44(a PRIMARY KEY);
7d97b9
+  INSERT INTO sqlite_stat1 VALUES('t44',null,'sz=0');
7d97b9
+  ANALYZE sqlite_master;
7d97b9
+  SELECT 0 FROM t44 WHERE a IN(1,2,3);
7d97b9
+} {} 
7d97b9
+
7d97b9
 
7d97b9
 # The sz=NNN parameter works even if there is other extraneous text
7d97b9
 # in the sqlite_stat1.stat column.
7d97b9
-- 
7d97b9
2.24.1
7d97b9