Sqlite: fix segfault on bad/missing sqlite_dbfile. Bug 2606
authorJeremy Harris <jgh146exb@wizmail.org>
Sun, 28 Jun 2020 14:24:21 +0000 (15:24 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Sun, 28 Jun 2020 17:10:37 +0000 (18:10 +0100)
(cherry picked from commit 3d0472791a0928963a3f8184fe28479e80d1a47d)

doc/doc-txt/ChangeLog
src/src/lookups/sqlite.c
test/scripts/2600-SQLite/2600
test/stderr/2600
test/stdout/2600

index bae9abb85e432568743552578f820a88939b2d51..8a13bda87ab348f5d97e939ae39a64008c14224a 100644 (file)
@@ -52,6 +52,9 @@ JH/11 Bug 2604: Fix request to cutthrough-deliver when a connection is already
 JH/13 Fix dsearch "subdir" filter to ignore ".".  Previously only ".." was
       excluded, not matching the documentation.
 
+JH/14 Bug 2606: Fix a segfault in sqlite lookups.  When no, or a bad, filename
+      was given for the sqlite_dbfile a trap resulted.
+
 
 Exim version 4.94
 -----------------
index dc4439153bd991650855d068405fbf99284fd1cb..1638ea4019d6b0ccd86b4ec2c4ba6630f55ffd42 100644 (file)
@@ -24,16 +24,23 @@ sqlite_open(const uschar * filename, uschar ** errmsg)
 sqlite3 *db = NULL;
 int ret;
 
-if (!filename || !*filename) filename = sqlite_dbfile;
-if (*filename != '/')
+if (!filename || !*filename)
+  {
+  DEBUG(D_lookup) debug_printf_indent("Using sqlite_dbfile: %s\n", sqlite_dbfile);
+  filename = sqlite_dbfile;
+  }
+if (!filename || *filename != '/')
   *errmsg = US"absolute file name expected for \"sqlite\" lookup";
 else if ((ret = sqlite3_open(CCS filename, &db)) != 0)
   {
   *errmsg = (void *)sqlite3_errmsg(db);
+  sqlite3_close(db);
+  db = NULL;
   DEBUG(D_lookup) debug_printf_indent("Error opening database: %s\n", *errmsg);
   }
 
-sqlite3_busy_timeout(db, 1000 * sqlite_lock_timeout);
+if (db)
+  sqlite3_busy_timeout(db, 1000 * sqlite_lock_timeout);
 return db;
 }
 
index 2a557a46ac2e6ebb2a02a4ef0b3e1177118001dc..2c3092ef210db14bc1d0047f0db4e3bcf4c4d1f1 100644 (file)
@@ -35,3 +35,9 @@ ${lookup sqlite{DIR/aux-fixed/sqlitedb select name from them where id='userx';}}
 exim -DDATA=DIR/aux-fixed/sqlitedb -d-all+lookup -be
 ${lookup sqlite{select name from them where id='userx';}}
 ****
+exim -DDATA=nonabsolute_filename -d-all+lookup -be
+${lookup sqlite{select name from them where id='userx';}}
+****
+exim -DDATA=DIR/missingfile -d-all+lookup -be
+${lookup sqlite{select name from them where id='userx';}}
+****
index 399fa0adb84ad07fcbb1165ccf32da6de60f4e93..a8bba488d46de1a56fdde02e61f689d2db56f57f 100644 (file)
@@ -489,6 +489,7 @@ configuration file is TESTSUITE/test-config
 admin user
 dropping to exim gid; retaining priv uid
  search_open: sqlite "NULL"
+ Using sqlite_dbfile: TESTSUITE/aux-fixed/sqlitedb
  search_find: file="NULL"
    key="select name from them where id='userx';" partial=-1 affix=NULL starflags=0 opts=NULL
  LRU list:
@@ -498,3 +499,27 @@ dropping to exim gid; retaining priv uid
  lookup yielded: Ayen Other
 search_tidyup called
 >>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+admin user
+dropping to exim gid; retaining priv uid
+ search_open: sqlite "NULL"
+ Using sqlite_dbfile: nonabsolute_filename
+search_tidyup called
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+admin user
+dropping to exim gid; retaining priv uid
+ search_open: sqlite "NULL"
+ Using sqlite_dbfile: TESTSUITE/missingfile
+ search_find: file="NULL"
+   key="select name from them where id='userx';" partial=-1 affix=NULL starflags=0 opts=NULL
+ LRU list:
+ internal_search_find: file="NULL"
+   type=sqlite key="select name from them where id='userx';" opts=NULL
+ database lookup required for select name from them where id='userx';
+ sqlite3_exec failed: no such table: them
+ lookup failed
+search_tidyup called
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
index 53d6b9b23bbccdfba7e3505ca54e4aed7e2efb2c..4116be7a7526c8de2650dfcef94f8f5bf7e5f492 100644 (file)
@@ -34,3 +34,7 @@ after" id=newline
 > 
 > Ayen Other
 > 
+> Failed: absolute file name expected for "sqlite" lookup
+> 
+> 
+>