[exim-cvs] Hintsdb: fix dumpdb for sqlite

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Exim Git Commits Mailing List
Ημερομηνία:  
Προς: exim-cvs
Αντικείμενο: [exim-cvs] Hintsdb: fix dumpdb for sqlite
Gitweb: https://git.exim.org/exim.git/commitdiff/b8a84c728b30b9d4736e9a37a2e3d3ca62684d23
Commit:     b8a84c728b30b9d4736e9a37a2e3d3ca62684d23
Parent:     459315d9e400695d3cf6e256e579f7e41e6533b3
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sat Jun 29 09:18:52 2024 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sat Jun 29 09:18:52 2024 +0100


    Hintsdb: fix dumpdb for sqlite
---
 src/src/exim_dbutil.c                    |  2 +-
 src/src/hintsdb/hints_sqlite.h           | 24 +++++++++++++++---------
 test/log/0128                            |  2 +-
 test/msglog/0128.10HmaX-000000005vi-0000 |  2 +-
 test/runtest                             |  9 +++------
 test/stdout/0543                         |  2 +-
 6 files changed, 22 insertions(+), 19 deletions(-)


diff --git a/src/src/exim_dbutil.c b/src/src/exim_dbutil.c
index 397b1162e..d3d854dd5 100644
--- a/src/src/exim_dbutil.c
+++ b/src/src/exim_dbutil.c
@@ -344,7 +344,7 @@ if (flags & O_RDWR) flags |= O_CREAT;

 if (!(dbblock->dbptr = exim_dbopen(filename, dirname, flags, 0)))
   {
-  printf("** Failed to open DBM file %s for %s: %s%s\n", filename,
+  printf("** Failed to open hintsdb file %s for %s: %s%s\n", filename,
     read_only ? "reading" : "writing", strerror(errno),
 #ifdef USE_DB
     " (or Berkeley DB error while opening)"
diff --git a/src/src/hintsdb/hints_sqlite.h b/src/src/hintsdb/hints_sqlite.h
index 21ebd4f01..69f9c43c1 100644
--- a/src/src/hintsdb/hints_sqlite.h
+++ b/src/src/hintsdb/hints_sqlite.h
@@ -99,9 +99,10 @@ if (sqlite3_step(statement) != SQLITE_ROW)


res->len = sqlite3_column_bytes(statement, 0);
# ifdef COMPILE_UTILITY
-res->data = malloc(res->len);
+if (!(res->data = malloc(res->len +1)))
+ { sqlite3_finalize(statement); return FALSE; }
# else
-res->data = store_get(res->len, GET_TAINTED);
+res->data = store_get(res->len +1, GET_TAINTED);
# endif
memcpy(res->data, sqlite3_column_blob(statement, 0), res->len);
res->data[res->len] = '\0';
@@ -120,7 +121,9 @@ BOOL ret;

 # ifdef COMPILE_UTILITY
 /* fprintf(stderr, "exim_dbget(k len %d '%.*s')\n", (int)key->len, (int)key->len, key->data); */
-qry = malloc(i = snprintf(NULL, 0, FMT, (int) key->len, key->data));
+i = snprintf(NULL, 0, FMT, (int) key->len, key->data)+1;
+if (!(qry = malloc(i)))
+  return FALSE;
 snprintf(CS qry, i, FMT, (int) key->len, key->data);
 ret = exim_dbget__(dbp, qry, res);
 free(qry);
@@ -143,19 +146,20 @@ exim_s_dbp(EXIM_DB * dbp, EXIM_DATUM * key, EXIM_DATUM * data, const uschar * al
 {
 int hlen = data->len * 2, off = 0, res;
 # define FMT "INSERT OR %s INTO tbl (ky,dat) VALUES ('%.*s', X'%.*s');"
+uschar * qry;
 # ifdef COMPILE_UTILITY
 uschar * hex = malloc(hlen+1);
+if (!hex) return EXIM_DBPUTB_DUP;    /* best we can do */
 # else
 uschar * hex = store_get(hlen+1, data->data);
 # endif
-uschar * qry;


for (const uschar * s = data->data, * t = s + data->len; s < t; s++, off += 2)
sprintf(CS hex + off, "%02X", *s);

# ifdef COMPILE_UTILITY
-res = snprintf(CS hex, 0, FMT, alt, (int) key->len, key->data, hlen, hex);
-qry = malloc(res);
+res = snprintf(CS hex, 0, FMT, alt, (int) key->len, key->data, hlen, hex) +1;
+if (!(qry = malloc(res))) return EXIM_DBPUTB_DUP;
snprintf(CS qry, res, FMT, alt, (int) key->len, key->data, hlen, hex);
/* fprintf(stderr, "exim_s_dbp(%s)\n", qry); */
res = sqlite3_exec(dbp, CS qry, NULL, NULL, NULL);
@@ -204,8 +208,8 @@ uschar * qry;
int res;

# ifdef COMPILE_UTILITY
-res = snprintf(NULL, 0, FMT, (int) key->len, key->data); /* res excludes nul */
-qry = malloc(res);
+res = snprintf(NULL, 0, FMT, (int) key->len, key->data) +1; /* res includes nul */
+if (!(qry = malloc(res))) return SQLITE_NOMEM;
snprintf(CS qry, res, FMT, (int) key->len, key->data);
res = sqlite3_exec(dbp, CS qry, NULL, NULL, NULL);
free(qry);
@@ -227,6 +231,7 @@ exim_dbcreate_cursor(EXIM_DB * dbp)
{
# ifdef COMPILE_UTILITY
EXIM_CURSOR * c = malloc(sizeof(int));
+if (!c) return NULL;
# else
EXIM_CURSOR * c = store_malloc(sizeof(int));
# endif
@@ -246,7 +251,8 @@ int i;
BOOL ret;

# ifdef COMPILE_UTILITY
-if (!(qry = malloc((i = snprintf(NULL, 0, FMT, *cursor))+1))) return FALSE;
+i = snprintf(NULL, 0, FMT, *cursor)+1;
+if (!(qry = malloc(i))) return FALSE;
snprintf(CS qry, i, FMT, *cursor);
/* fprintf(stderr, "exim_dbscan(%s)\n", qry); */
ret = exim_dbget__(dbp, qry, key);
diff --git a/test/log/0128 b/test/log/0128
index 58f770eb9..a267f684d 100644
--- a/test/log/0128
+++ b/test/log/0128
@@ -1,2 +1,2 @@
1999-03-02 09:44:33 10HmaX-000000005vi-0000 <= CALLER@??? U=CALLER P=local S=sss
-1999-03-02 09:44:33 10HmaX-000000005vi-0000 == userx@??? R=reply T=reply defer (EEE): Is a directory: Failed to open DBM file TESTSUITE/spool when sending message from reply transport: Is a directory
+1999-03-02 09:44:33 10HmaX-000000005vi-0000 == userx@??? R=reply T=reply defer (EEE): Is a directory: Failed to open sqlite3 file TESTSUITE/spool when sending message from reply transport: Is a directory
diff --git a/test/msglog/0128.10HmaX-000000005vi-0000 b/test/msglog/0128.10HmaX-000000005vi-0000
index 930261ebb..4687b60df 100644
--- a/test/msglog/0128.10HmaX-000000005vi-0000
+++ b/test/msglog/0128.10HmaX-000000005vi-0000
@@ -1,2 +1,2 @@
1999-03-02 09:44:33 Received from CALLER@??? U=CALLER P=local S=sss
-1999-03-02 09:44:33 userx@??? R=reply T=reply defer (EEE): Is a directory: Failed to open DBM file TESTSUITE/spool when sending message from reply transport: Is a directory
+1999-03-02 09:44:33 userx@??? R=reply T=reply defer (EEE): Is a directory: Failed to open sqlite3 file TESTSUITE/spool when sending message from reply transport: Is a directory
diff --git a/test/runtest b/test/runtest
index 7a642fc20..781ea97d1 100755
--- a/test/runtest
+++ b/test/runtest
@@ -468,9 +468,6 @@ RESET_AFTER_EXTRA_LINE_READ:
# This message sometimes has a different number of seconds
s/forced fail after \d seconds/forced fail after d seconds/;

- # This message may contain a different DBM library name
- s/Failed to open \S+( \([^\)]+\))? file/Failed to open DBM file/;
-
# The message for a non-listening FIFO varies
s/:[^:]+: while opening named pipe/: Error: while opening named pipe/;

@@ -1056,7 +1053,7 @@ RESET_AFTER_EXTRA_LINE_READ:
     s/^(Connection request from) \[.*:.*:.*\]$/$1 \[ipv6\]/;


     # Hints DB use of lockfiles is provider-dependent
-    s/Failed to open \K(?:DBM|database lock) file (.*\/spool\/db\/[^.]*)(?:.lockfile)?(?=(?: for reading)?: No such file or directory$)/hintsdb $1/;
+    s/Failed to open \K(?:hintsdb|database lock) file (.*\/spool\/db\/[^.]*)(?:.lockfile)?(?=(?: for reading)?: No such file or directory$)/hintsdb $1/;


     # openssl version variances
   # Error lines on stdout from SSL contain process id values and file names.
@@ -2470,7 +2467,7 @@ if ($debug) { printf ">> $_\n"; }
 ###################


# The "dbmbuild" command runs exim_dbmbuild. This is used both to test the
-# utility and to make DBM files for testing DBM lookups.
+# utility and to make hintsdb files for testing hintsdb lookups.

if (/^dbmbuild\s+(\S+)\s+(\S+)/)
{
@@ -2483,7 +2480,7 @@ if (/^dbmbuild\s+(\S+)\s+(\S+)/)

# The "dump" command runs exim_dumpdb. On different systems, the output for
# some types of dump may appear in a different order because it's just hauled
-# out of the DBM file. We can solve this by sorting. Ignore the leading
+# out of the hintsdb file. We can solve this by sorting. Ignore the leading
# date/time, as it will be flattened later during munging.

if (/^dump\s+(\S+)/)
diff --git a/test/stdout/0543 b/test/stdout/0543
index c53cb62ad..d51549ac9 100644
--- a/test/stdout/0543
+++ b/test/stdout/0543
@@ -1,5 +1,5 @@
+++++++++++++++++++++++++++
-** Failed to open hintsdb TESTSUITE/spool/db/wait-smtp: No such file or directory
+** Failed to open hintsdb TESTSUITE/spool/db/wait-smtp for reading: No such file or directory

******** SERVER ********
Listening on port 1224 ...

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-cvs.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-cvs-unsubscribe@???
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/