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

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