From 35c22ec7c2bd08ba6631e29769a8ece18cbc76c0 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 23 Jul 2024 13:26:24 +0100 Subject: [PATCH] Fix dbmjz lookup Broken-by: c66a6edf7ba8 --- src/src/dbfn.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/src/dbfn.c b/src/src/dbfn.c index 16b300180..1044611cc 100644 --- a/src/src/dbfn.c +++ b/src/src/dbfn.c @@ -376,14 +376,13 @@ DEBUG(D_hints_lookup) * Read from database file * *************************************************/ -/* Passing back the pointer unchanged is useless, because there is +/* Read, using a defined-length key (permitting embedded NULs). + +Passing back the pointer unchanged is useless, because there is no guarantee of alignment. Since all the records used by Exim need to be properly aligned to pick out the timestamps, etc., we might as well do the copying centrally here. -Most calls don't need the length, so there is a macro called dbfn_read which -has two arguments; it calls this function adding NULL as the third. - Arguments: dbblock a pointer to an open database block key the key of the record to be read @@ -421,9 +420,11 @@ if (!exim_dbget(dbblock->dbptr, &key_datum, &result_datum)) store the taint status with the data. */ dlen = exim_datum_size_get(&result_datum); -yield = store_get(dlen, GET_TAINTED); -memcpy(yield, exim_datum_data_get(&result_datum), dlen); DEBUG(D_hints_lookup) debug_printf_indent("dbfn_read: size %u return\n", dlen); + +yield = store_get(dlen+1, GET_TAINTED); +memcpy(yield, exim_datum_data_get(&result_datum), dlen); +((uschar *)yield)[dlen] = '\0'; if (length) *length = dlen; exim_datum_free(&result_datum); /* Some DBM libs require freeing */ @@ -431,7 +432,11 @@ return yield; } -/* +/* Read, using a NUL-terminated key. + +Most calls don't need the length, so there is a macro called dbfn_read which +has two arguments; it calls this function adding NULL as the third. + Arguments: dbblock a pointer to an open database block key the key of the record to be read (NUL-terminated) -- 2.30.2