Fix dmbjz on sqlite
[exim.git] / src / src / dbfn.c
index 16b300180b17e0ae6cb30f9fc0cd3cc42b6b49d2..1d24769dbf20f6b202f5f7b9966c30dd559698cb 100644 (file)
@@ -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)
@@ -533,7 +538,7 @@ Returns: the yield of the underlying dbm or db "delete" function.
 int
 dbfn_delete(open_db *dbblock, const uschar *key)
 {
-int klen = Ustrlen(key) + 1;
+int klen = Ustrlen(key) + 1, rc;
 uschar * key_copy = store_get(klen, key);
 EXIM_DATUM key_datum;
 
@@ -543,7 +548,10 @@ memcpy(key_copy, key, klen);
 exim_datum_init(&key_datum);         /* Some DBM libraries require clearing */
 exim_datum_data_set(&key_datum, key_copy);
 exim_datum_size_set(&key_datum, klen);
-return exim_dbdel(dbblock->dbptr, &key_datum);
+rc = exim_dbdel(dbblock->dbptr, &key_datum);
+DEBUG(D_hints_lookup) if (rc != EXIM_DBPUTB_OK)
+  debug_printf_indent(" exim_dbdel: fail\n");
+return rc;
 }
 
 
@@ -592,7 +600,7 @@ yield = exim_dbscan(dbblock->dbptr, &key_datum, &value_datum, start, *cursor)
 if (!yield) exim_dbdelete_cursor(*cursor);
 return yield;
 }
-#endif
+#endif /*notdef*/