Timo Sirainen [Thu, 29 Oct 2020 10:55:21 +0000 (12:55 +0200)]
imap: Fix potential hang if client disconnects with pipelined ambiguous commands
For example if client pipelines FETCH+LOGOUT commands and disconnects during
a large FETCH output, the LOGOUT command is processed as waiting for
unambiguity. This code path however doesn't detect a client disconnection,
and input IO handler is removed so it can't detect it either. So the imap
process hangs.
Timo Sirainen [Mon, 10 Aug 2020 14:33:07 +0000 (17:33 +0300)]
lib-index: mail_index_sync_map() - Always return -1 on I/O failures
Even though with force=FALSE in theory it would be possible to work around
it, but more likely it will just cause another I/O error. This simplifies
the code for the following changes.
Although the old code worked as well, it wasn't so obvious since the
behavior was slightly different when the log->head had extra references.
Clarify the behavior by always unreferencing after the new log file is
created.
Timo Sirainen [Mon, 10 Aug 2020 16:54:55 +0000 (19:54 +0300)]
lib-index: mail_transaction_log_view_set() - Make sure log files aren't freed too early
It's possible that mail_transaction_log_find_file() frees one of the files
that are already in the linked list. Avoid it by referencing the file
immediately when it's added to the list.
Timo Sirainen [Mon, 10 Aug 2020 14:12:32 +0000 (17:12 +0300)]
lib-index: mail_transaction_log_view_set() - Return -1 only on I/O error
The callers that care about the difference:
* mail_index_sync_map() already assumes that -1 means I/O error
* mail_index_sync_set_log_view() handles 0 by logging an error and fscking
the index, which is likely better than just returning failure.
* view_sync_set_log_view_range()'s caller handles 0 by rebuilding the
missing changes in memory. So returning 0 makes it work better.
* dsync_log_set() and mailbox_get_expunges_init() have fallbacks for
handling 0, while -1 would just return an error.
Markus Valentin [Fri, 20 Nov 2020 11:52:47 +0000 (12:52 +0100)]
doveadm: mail: doveadm_mail_failed_error() - Set specific exit code for MAIL_ERROR_INUSE
Set exit code DOVEADM_EX_NOTPOSSIBLE in case MAIL_ERROR_INUSE is set via
doveadm_mail_failed_error(). This exit code is used to indicate that a
operation cannot be done because another session prevents it.
Timo Sirainen [Fri, 20 Nov 2020 10:15:18 +0000 (12:15 +0200)]
doveadm: When sending server logs to client, make sure ioloop isn't set to NULL
This could have happened if there was any logging done outside command
handling. For example a doveadm command used http-client, which has a
timeout that triggers logging only after the command is finished.
lib: event-filter - Do not assert that there in no output on error
When the input is a simple (but invalid) expression (e.g., a=b=c) the output
variable may be set. This is perfectly fine.
The assertion (and the associated failure) come from when event filter
parsing was switched to the new filter syntax
(fcba1d530737813de11d9d730d5db6496e2e574b).
Timo Sirainen [Tue, 10 Nov 2020 22:11:35 +0000 (00:11 +0200)]
dsync: Fix UID renumbering when GUIDs aren't used
Mails that have local UIDs won't be in import_uids hash table, so they're
not otherwise being iterated at the end and checked if they need
renumbering.
Timo Sirainen [Mon, 2 Nov 2020 16:55:16 +0000 (18:55 +0200)]
lib-index: Fix detecting if index is undeleted
It was possible that mail_index_is_deleted() kept returning that the index
was deleted, even if it was marked as undeleted. This happened when the
deletion was in dovecot.index.log.2, undeletion in dovecot.index.log and
dovecot.index pointed to the .log.2 file. This caused the .log file to be
read first, which sees the undeletion. Later on the .log.2 was parsed and
it marked the index back as deleted.
Timo Sirainen [Mon, 9 Nov 2020 16:10:21 +0000 (18:10 +0200)]
lib-smtp: smtp_address_init_from_msg() - Avoid implicit char to unsigned char conversion
Fixes calling smtp_char_is_qpair() with ubsan:
runtime error: implicit conversion from type 'char' of value -61 (8-bit, signed) to type 'unsigned char' changed the value to 195 (8-bit, unsigned)
Timo Sirainen [Mon, 9 Nov 2020 15:52:51 +0000 (17:52 +0200)]
lib-index: Add explicit wrapping to 8bit variable increments
Fixes ubsan errors:
runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned)
Timo Sirainen [Mon, 9 Nov 2020 14:09:05 +0000 (16:09 +0200)]
lib: Add and use TYPE_CHECKS() macro to standardize type checking for functions
This helps especially to avoid adding COMPILE_ERROR_*() macros to NULL
pointers, which results in ubsan errors:
runtime error: applying zero offset to null pointer
These changes also remove the use of gcc-specific ({...}) code in the
macros, making them slightly more portable.
Timo Sirainen [Mon, 9 Nov 2020 11:04:43 +0000 (13:04 +0200)]
lib-fs: fs_file_init_parent() - Keep mode and flags parameters separated
Internally cast them both to (int) before ORing them together for the
fs_file_init_with_event() call.
This avoids compiler warnings with -Wenum-enum-conversion:
warning: bitwise operation between different enumeration types ('enum fs_open_mode' and 'enum fs_open_flags')
Aki Tuomi [Thu, 22 Oct 2020 08:42:23 +0000 (11:42 +0300)]
auth: db-oauth2 - Change active:false to mean invalid token
Specifications say that invalid token, expired token and any other
reason why the token can be considered invalid should return
{"active":false} reply with no other fields.
Fixes:
warning: suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma? [-Wstring-concatenation]
Timo Sirainen [Thu, 29 Oct 2020 10:33:14 +0000 (12:33 +0200)]
lib: Standardize STMT_BEGIN and STMT_END
do .. while(0) should work everywhere.
This also fixes warnings given by new clang:
warning: '}' and ')' tokens terminating statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]