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

ec7966
From 6b06304c2a46e17a6dc4402eadc75ccac24da893 Mon Sep 17 00:00:00 2001
ec7966
From: Ondrej Dubaj <odubaj@redhat.com>
ec7966
Date: Fri, 17 Jan 2020 13:03:54 +0100
ec7966
Subject: [PATCH] When an error occurs while rewriting the parser tree for
ec7966
 window functions in the sqlite3WindowRewrite() routine, make sure that
ec7966
 pParse->nErr is set, and make sure that this shuts down any subsequent code
ec7966
 generation that might depend on the transformations that were implemented. 
ec7966
 This fixes a problem discovered by the Yongheng and Rui fuzzer.
ec7966
ec7966
---
ec7966
 src/expr.c    | 1 +
ec7966
 src/vdbeaux.c | 3 ++-
ec7966
 src/window.c  | 5 +++++
ec7966
 3 files changed, 8 insertions(+), 1 deletion(-)
ec7966
ec7966
diff --git a/src/expr.c b/src/expr.c
ec7966
index d4eb9de..b081ca2 100644
ec7966
--- a/src/expr.c
ec7966
+++ b/src/expr.c
ec7966
@@ -344,6 +344,7 @@ static int codeCompare(
ec7966
   int addr;
ec7966
   CollSeq *p4;
ec7966
 
ec7966
+  if( pParse->nErr ) return 0;
ec7966
   p4 = sqlite3BinaryCompareCollSeq(pParse, pLeft, pRight);
ec7966
   p5 = binaryCompareP5(pLeft, pRight, jumpIfNull);
ec7966
   addr = sqlite3VdbeAddOp4(pParse->pVdbe, opcode, in2, dest, in1,
ec7966
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
ec7966
index f1496a3..b74141b 100644
ec7966
--- a/src/vdbeaux.c
ec7966
+++ b/src/vdbeaux.c
ec7966
@@ -1160,7 +1160,8 @@ void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
ec7966
 */
ec7966
 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
ec7966
   assert( p->nOp>0 || p->aOp==0 );
ec7966
-  assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
ec7966
+  assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
ec7966
+          || p->pParse->nErr>0 );
ec7966
   if( p->nOp ){
ec7966
     assert( p->aOp );
ec7966
     sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
ec7966
diff --git a/src/window.c b/src/window.c
ec7966
index f5deae9..56c0145 100644
ec7966
--- a/src/window.c
ec7966
+++ b/src/window.c
ec7966
@@ -843,6 +843,11 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){
ec7966
     if( db->mallocFailed ) rc = SQLITE_NOMEM;
ec7966
   }
ec7966
 
ec7966
+  if( rc && pParse->nErr==0 ){
ec7966
+    assert( pParse->db->mallocFailed );
ec7966
+    return SQLITE_NOMEM;
ec7966
+  }
ec7966
+
ec7966
   return rc;
ec7966
 }
ec7966
 
ec7966
-- 
ec7966
2.19.1
ec7966