Blame SOURCES/sqlite-3.26.0-zPath-covscan.patch

032533
From 75525dbdf9b7ed003e343c42710e8b13f73a7607 Mon Sep 17 00:00:00 2001
032533
From: Ondrej Dubaj <odubaj@redhat.com>
032533
Date: Thu, 23 Jan 2020 15:08:13 +0100
032533
Subject: [PATCH] Fix buffer underflows in the zipfile extension associated
032533
 with zero-length or NULL filename in the ZIP archive. But report on the
032533
 mailing list by Yongheng and Rui.
032533
032533
---
032533
 ext/misc/zipfile.c | 14 +++++++++-----
032533
 test/zipfile.test  | 13 +++++++++++++
032533
 2 files changed, 22 insertions(+), 5 deletions(-)
032533
032533
diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c
032533
index e6141ef..7fd4074 100644
032533
--- a/ext/misc/zipfile.c
032533
+++ b/ext/misc/zipfile.c
032533
@@ -1433,8 +1433,8 @@ static int zipfileGetMode(
032533
 ** identical, ignoring any trailing '/' character in either path.  */
032533
 static int zipfileComparePath(const char *zA, const char *zB, int nB){
032533
   int nA = (int)strlen(zA);
032533
-  if( zA[nA-1]=='/' ) nA--;
032533
-  if( zB[nB-1]=='/' ) nB--;
032533
+  if( nA>0 && zA[nA-1]=='/' ) nA--;
032533
+  if( nB>0 && zB[nB-1]=='/' ) nB--;
032533
   if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
032533
   return 1;
032533
 }
032533
@@ -1628,11 +1628,15 @@ static int zipfileUpdate(
032533
       ** '/'. This appears to be required for compatibility with info-zip
032533
       ** (the unzip command on unix). It does not create directories
032533
       ** otherwise.  */
032533
-      if( zPath[nPath-1]!='/' ){
032533
+      if( nPath<=0 || zPath[nPath-1]!='/' ){
032533
         zFree = sqlite3_mprintf("%s/", zPath);
032533
-        if( zFree==0 ){ rc = SQLITE_NOMEM; }
032533
         zPath = (const char*)zFree;
032533
-        nPath = (int)strlen(zPath);
032533
+        if( zFree==0 ){
032533
+          rc = SQLITE_NOMEM;
032533
+          nPath = 0;
032533
+        }else{
032533
+          nPath = (int)strlen(zPath);
032533
+        }
032533
       }
032533
     }
032533
 
032533
diff --git a/test/zipfile.test b/test/zipfile.test
032533
index e4b8088..9f07c0a 100644
032533
--- a/test/zipfile.test
032533
+++ b/test/zipfile.test
032533
@@ -821,4 +821,17 @@ do_execsql_test 14.10 {
032533
   PRAGMA integrity_check;
032533
 } {3 ok}
032533
 
032533
+# 2019-12-26 More problems in zipfile from the Yongheng and Rui fuzzer
032533
+#
032533
+do_execsql_test 15.10 {
032533
+  DROP TABLE IF EXISTS t1;
032533
+  CREATE VIRTUAL TABLE t1 USING zipfile(null);
032533
+  REPLACE INTO t1 VALUES(null,null,0,null,null,null,null);
032533
+} {}
032533
+do_execsql_test 15.20 {
032533
+  DROP TABLE IF EXISTS t2;
032533
+  CREATE VIRTUAL TABLE t2 USING zipfile(null);
032533
+  REPLACE INTO t2 values(null,null,null,null,null,10,null);
032533
+} {}
032533
+
032533
 finish_test
032533
-- 
032533
2.19.1
032533