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

a87669
From ff5f246e41239cc4dd33ffa73883fa07f78674e1 Mon Sep 17 00:00:00 2001
ec7966
From: Ondrej Dubaj <odubaj@redhat.com>
a87669
Date: Fri, 7 Aug 2020 07:00:29 +0200
ec7966
Subject: [PATCH] Do not attempt to unwind the WITH stack in the Parse object
ec7966
 following an error.
ec7966
ec7966
---
a87669
 src/select.c        |  5 ++++-
a87669
 src/util.c          |  1 +
a87669
 test/altertab2.test | 20 ++++++++++++++++++++
a87669
 test/with3.test     | 10 +++++++++-
a87669
 4 files changed, 34 insertions(+), 2 deletions(-)
ec7966
ec7966
diff --git a/src/select.c b/src/select.c
a87669
index c46f177..a6d1757 100644
ec7966
--- a/src/select.c
ec7966
+++ b/src/select.c
a87669
@@ -4639,6 +4639,9 @@ static int withExpand(
a87669
   With *pWith;                    /* WITH clause that pCte belongs to */
a87669
 
a87669
   assert( pFrom->pTab==0 );
a87669
+  if( pParse->nErr ){
a87669
+    return SQLITE_ERROR;
a87669
+  }
a87669
 
a87669
   pCte = searchWith(pParse->pWith, pFrom, &pWith);
a87669
   if( pCte ){
a87669
@@ -4908,7 +4911,7 @@ static int selectExpander(Walker *pWalker, Select *p){
ec7966
 
ec7966
   /* Process NATURAL keywords, and ON and USING clauses of joins.
ec7966
   */
ec7966
-  if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
ec7966
+  if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
ec7966
     return WRC_Abort;
ec7966
   }
ec7966
 
a87669
diff --git a/src/util.c b/src/util.c
a87669
index 54f9b93..96b0b14 100644
a87669
--- a/src/util.c
a87669
+++ b/src/util.c
a87669
@@ -222,6 +222,7 @@ void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
a87669
     sqlite3DbFree(db, pParse->zErrMsg);
a87669
     pParse->zErrMsg = zMsg;
a87669
     pParse->rc = SQLITE_ERROR;
a87669
+    pParse->pWith = 0;
a87669
   }
a87669
 }
a87669
 
a87669
diff --git a/test/altertab2.test b/test/altertab2.test
a87669
index 2e4212c..2102e02 100644
a87669
--- a/test/altertab2.test
a87669
+++ b/test/altertab2.test
a87669
@@ -85,5 +85,25 @@ do_execsql_test 2.3 {
a87669
   {CREATE TABLE c3(x, FOREIGN KEY (x) REFERENCES "p3"(a))}
a87669
 }
a87669
 
a87669
+#------------------------------------------------------------------------
a87669
+#
a87669
+reset_db
a87669
+do_execsql_test 3.0 {
a87669
+  CREATE TABLE v0 (a);
a87669
+  CREATE VIEW v2 (v3) AS 
a87669
+    WITH x1 AS (SELECT * FROM v2) 
a87669
+    SELECT v3 AS x, v3 AS y FROM v2; 
a87669
+}
a87669
+
a87669
+do_catchsql_test 3.1 {
a87669
+  SELECT * FROM v2
a87669
+} {1 {view v2 is circularly defined}}
a87669
+
a87669
+db close
a87669
+sqlite3 db test.db
a87669
+
a87669
+do_catchsql_test 3.2 {
a87669
+  ALTER TABLE v0 RENAME TO t3 ;
a87669
+} {1 {error in view v2: view v2 is circularly defined}}
a87669
 
a87669
 finish_test
a87669
diff --git a/test/with3.test b/test/with3.test
a87669
index de150b1..4a3a5a7 100644
a87669
--- a/test/with3.test
a87669
+++ b/test/with3.test
a87669
@@ -30,7 +30,15 @@ do_catchsql_test 1.0 {
a87669
     SELECT 5 FROM t0 UNION SELECT 8 FROM m
a87669
   )
a87669
   SELECT * FROM i;
a87669
-} {1 {no such table: m}}
a87669
+} {1 {no such table: t0}}
a87669
+
a87669
+# 2019-11-09 dbfuzzcheck find
a87669
+do_catchsql_test 1.1 {
a87669
+  CREATE VIEW v1(x,y) AS
a87669
+    WITH t1(a,b) AS (VALUES(1,2))
a87669
+    SELECT * FROM nosuchtable JOIN t1;
a87669
+  SELECT * FROM v1;
a87669
+} {1 {no such table: main.nosuchtable}}
a87669
 
a87669
 # Additional test cases that came out of the work to
a87669
 # fix for Kostya's problem.
ec7966
-- 
a87669
2.26.0
ec7966