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

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