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

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