Gitweb:
https://git.exim.org/exim.git/commitdiff/9bf74b9c298f6968417fe88a68ccdf2179db1403
Commit: 9bf74b9c298f6968417fe88a68ccdf2179db1403
Parent: f3fe5970b320bd6f8c9d01f11881fa6d6b5e7384
Author: Jeremy Harris <jgh146exb@???>
AuthorDate: Sat Jun 29 09:28:25 2024 +0100
Committer: Jeremy Harris <jgh146exb@???>
CommitDate: Sat Jun 29 11:31:48 2024 +0100
Hintsdb: fix dumpdb for sqlite
---
src/src/exim_dbutil.c | 2 +-
src/src/hintsdb.h | 24 +++++++++++++++---------
test/log/0128 | 2 +-
test/msglog/0128.10HmaX-000000005vi-0000 | 2 +-
test/runtest | 4 ++--
5 files changed, 20 insertions(+), 14 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.h b/src/src/hintsdb.h
index 3fedfabca..a6555ed25 100644
--- a/src/src/hintsdb.h
+++ b/src/src/hintsdb.h
@@ -145,9 +145,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';
@@ -166,7 +167,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);
@@ -189,19 +192,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);
@@ -250,8 +254,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);
@@ -273,6 +277,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
@@ -292,7 +297,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..467ce6984 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 hintsdb 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..e4107932a 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 hintsdb file TESTSUITE/spool when sending message from reply transport: Is a directory
diff --git a/test/runtest b/test/runtest
index d205f9509..0c5f69a93 100755
--- a/test/runtest
+++ b/test/runtest
@@ -469,7 +469,7 @@ RESET_AFTER_EXTRA_LINE_READ:
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/;
+ s/Failed to open \S+( \([^\)]+\))? file/Failed to open hintsdb file/;
# The message for a non-listening FIFO varies
s/:[^:]+: while opening named pipe/: Error: while opening named pipe/;
@@ -1056,7 +1056,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.
--
## 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/