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

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