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

094f44
From 16c5290d72cb8059e9dfe545613183b850fc44e4 Mon Sep 17 00:00:00 2001
094f44
From: Ondrej Dubaj <odubaj@redhat.com>
094f44
Date: Mon, 20 Jan 2020 10:26:35 +0100
094f44
Subject: [PATCH] Fix the zipfile() function in the zipfile extension so that
094f44
 it is able to
094f44
094f44
deal with goofy filenames that contain embedded zeros.
094f44
---
094f44
 ext/misc/zipfile.c |  4 ++--
094f44
 test/zipfile.test  | 13 +++++++++++++
094f44
 2 files changed, 15 insertions(+), 2 deletions(-)
094f44
094f44
diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c
094f44
index 6f48d0f..e6141ef 100644
094f44
--- a/ext/misc/zipfile.c
094f44
+++ b/ext/misc/zipfile.c
094f44
@@ -1632,7 +1632,7 @@ static int zipfileUpdate(
094f44
         zFree = sqlite3_mprintf("%s/", zPath);
094f44
         if( zFree==0 ){ rc = SQLITE_NOMEM; }
094f44
         zPath = (const char*)zFree;
094f44
-        nPath++;
094f44
+        nPath = (int)strlen(zPath);
094f44
       }
094f44
     }
094f44
 
094f44
@@ -2033,11 +2033,11 @@ void zipfileStep(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
094f44
   }else{
094f44
     if( zName[nName-1]!='/' ){
094f44
       zName = zFree = sqlite3_mprintf("%s/", zName);
094f44
-      nName++;
094f44
       if( zName==0 ){
094f44
         rc = SQLITE_NOMEM;
094f44
         goto zipfile_step_out;
094f44
       }
094f44
+      nName = (int)strlen(zName);
094f44
     }else{
094f44
       while( nName>1 && zName[nName-2]=='/' ) nName--;
094f44
     }
094f44
diff --git a/test/zipfile.test b/test/zipfile.test
094f44
index 5bca10b..e4b8088 100644
094f44
--- a/test/zipfile.test
094f44
+++ b/test/zipfile.test
094f44
@@ -808,4 +808,17 @@ do_execsql_test 13.10 {
094f44
          quote(data),quote(method) FROM t1;
094f44
 } {'' 10 10 2 X'3130' X'3130' 0}
094f44
 
094f44
+# 2019-12-23 Yongheng and Rui fuzzer
094f44
+# Run using valgrind to see the problem.
094f44
+#
094f44
+do_execsql_test 14.10 {
094f44
+  DROP TABLE t1;
094f44
+  CREATE TABLE t1(x char);
094f44
+  INSERT INTO t1(x) VALUES('1');
094f44
+  INSERT INTO t1(x) SELECT zipfile(x, 'xyz') FROM t1;
094f44
+  INSERT INTO t1(x) SELECT zipfile(x, 'uvw') FROM t1;
094f44
+  SELECT count(*) FROM t1;
094f44
+  PRAGMA integrity_check;
094f44
+} {3 ok}
094f44
+
094f44
 finish_test
094f44
-- 
094f44
2.19.1
094f44