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

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