X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/de6f74f297d040a34746bc8e1829ad4b867441c9..5732024c9991f1e220ad203087997ca467a5cef7:/src/src/retry.c diff --git a/src/src/retry.c b/src/src/retry.c index 2404b0565..30b308fe3 100644 --- a/src/src/retry.c +++ b/src/src/retry.c @@ -3,6 +3,7 @@ *************************************************/ /* Copyright (c) University of Cambridge 1995 - 2018 */ +/* Copyright (c) The Exim Maintainers 2020 */ /* See the file NOTICE for conditions of use and distribution. */ /* Functions concerned with retrying unsuccessful deliveries. */ @@ -170,7 +171,7 @@ if ((node = tree_search(tree_unusable, host_key))) /* Open the retry database, giving up if there isn't one. Otherwise, search for the retry records, and then close the database again. */ -if (!(dbm_file = dbfn_open(US"retry", O_RDONLY, &dbblock, FALSE))) +if (!(dbm_file = dbfn_open(US"retry", O_RDONLY, &dbblock, FALSE, TRUE))) { DEBUG(D_deliver|D_retry|D_hints_lookup) debug_printf("no retry data available\n"); @@ -291,7 +292,7 @@ Returns: nothing void retry_add_item(address_item *addr, uschar *key, int flags) { -retry_item *rti = store_get(sizeof(retry_item)); +retry_item *rti = store_get(sizeof(retry_item), FALSE); host_item * host = addr->host_used; rti->next = addr->retries; @@ -523,7 +524,6 @@ retry_update(address_item **addr_defer, address_item **addr_failed, open_db dbblock; open_db *dbm_file = NULL; time_t now = time(NULL); -int i; DEBUG(D_retry) debug_printf("Processing retry items\n"); @@ -531,7 +531,7 @@ DEBUG(D_retry) debug_printf("Processing retry items\n"); Deferred addresses must be handled after failed ones, because some may be moved to the failed chain if they have timed out. */ -for (i = 0; i < 3; i++) +for (int i = 0; i < 3; i++) { address_item *endaddr, *addr; address_item *last_first = NULL; @@ -555,7 +555,6 @@ for (i = 0; i < 3; i++) while ((endaddr = *paddr)) { BOOL timed_out = FALSE; - retry_item *rti; for (addr = endaddr; addr; addr = addr->parent) { @@ -567,7 +566,7 @@ for (i = 0; i < 3; i++) /* Loop for each retry item. */ - for (rti = addr->retries; rti; rti = rti->next) + for (retry_item * rti = addr->retries; rti; rti = rti->next) { uschar *message; int message_length, message_space, failing_interval, next_try; @@ -582,7 +581,7 @@ for (i = 0; i < 3; i++) reached their retry next try time. */ if (!dbm_file) - dbm_file = dbfn_open(US"retry", O_RDWR, &dbblock, TRUE); + dbm_file = dbfn_open(US"retry", O_RDWR, &dbblock, TRUE, TRUE); if (!dbm_file) { @@ -661,14 +660,16 @@ for (i = 0; i < 3; i++) /* Read a retry record from the database or construct a new one. Ignore an old one if it is too old since it was last updated. */ - retry_record = dbfn_read(dbm_file, rti->key); + retry_record = dbfn_read_with_length(dbm_file, rti->key, + &message_space); if ( retry_record && now - retry_record->time_stamp > retry_data_expire) retry_record = NULL; if (!retry_record) { - retry_record = store_get(sizeof(dbdata_retry) + message_length); + retry_record = store_get(sizeof(dbdata_retry) + message_length, + is_tainted(message)); message_space = message_length; retry_record->first_failed = now; retry_record->last_try = now; @@ -676,7 +677,7 @@ for (i = 0; i < 3; i++) retry_record->expired = FALSE; retry_record->text[0] = 0; /* just in case */ } - else message_space = Ustrlen(retry_record->text); + else message_space -= sizeof(dbdata_retry); /* Compute how long this destination has been failing */ @@ -807,15 +808,17 @@ for (i = 0; i < 3; i++) if (next_try - now > retry_interval_max) next_try = now + retry_interval_max; - /* If the new message length is greater than the previous one, we - have to copy the record first. */ - - if (message_length > message_space) - { - dbdata_retry *newr = store_get(sizeof(dbdata_retry) + message_length); - memcpy(newr, retry_record, sizeof(dbdata_retry)); - retry_record = newr; - } + /* If the new message length is greater than the previous one, we have + to copy the record first. If we're using an old one, the read used + tainted memory so we're ok to write into it. */ + + if (message_length > message_space) + { + dbdata_retry * newr = + store_get(sizeof(dbdata_retry) + message_length, is_tainted(message)); + memcpy(newr, retry_record, sizeof(dbdata_retry)); + retry_record = newr; + } /* Set up the retry record; message_length may be less than the string length for very long error strings. */