If header with the same key already exists, just replace the value.
HTTP supports having multiple headers with the same key only when they
can be rewritten into a single comma-separated header. So practically
there's no reason for lib-http to need to support adding multiple
headers. Replacing an existing value is more useful generally.
Timo Sirainen [Fri, 17 May 2019 07:33:53 +0000 (10:33 +0300)]
lib-imap: Make sure str_unescape() won't be writing past allocated memory
The previous commit should already prevent this, but this makes sure it
can't become broken in the future either. It makes the performance a tiny
bit worse, but that's not practically noticeable.
Timo Sirainen [Fri, 10 May 2019 16:24:51 +0000 (19:24 +0300)]
lib-imap: Don't accept strings with NULs
IMAP doesn't allow NULs except in binary literals. We'll still allow them
in regular literals as well, but just not in strings.
This fixes a bug with unescaping a string with NULs: str_unescape() could
have been called for memory that points outside the allocated string,
causing heap corruption. This could cause crashes or theoretically even
result in remote code execution exploit.
Timo Sirainen [Tue, 15 Jan 2019 23:00:22 +0000 (01:00 +0200)]
LAYOUT=index: Fix rebuilding mailbox list index on force-resync
The if-check was a bit confusing because have_backend==TRUE means that there
the mailbox list index is only an index, while have_backend==FALSE means
that the mailbox list index is the only source for the list of mailboxes
(= list index is the backend).
Timo Sirainen [Tue, 2 Oct 2018 07:22:11 +0000 (10:22 +0300)]
lib-master: ipc-client: Don't free command too early
When multiple replies were received by IPC only the final reply should free
the command. This may have caused e.g. "doveadm proxy list" to crash.
Broken by 435f0545b200767c25a5daee17cd6b4998d03710
Timo Sirainen [Wed, 25 Jul 2018 10:17:45 +0000 (13:17 +0300)]
lib-storage: Fix bodystructure parsing crash if header is parsed twice
The second parsing will recreate the parser_ctx, discarding the old parsed
message_part.data for the header. On the second parsing
save_bodystructure_header=FALSE so the message_part.data isn't filled for
the header. Later on the bodystructure parsing assumes the data is set,
and crashes.
This only happened with mail_attachment_detection_options=add-flags-on-save
and Sieve script that first accessed a non-cached header and then used the
"body" extension.
Fixes segfault and also:
Panic: file imap-bodystructure.c: line 116 (part_write_body_multipart): assertion failed: (part->data != NULL)
Timo Sirainen [Tue, 24 Jul 2018 12:00:19 +0000 (15:00 +0300)]
lib-imap: Remove content_subtype==NULL checks
This can never happen after the previous commit. This also changes the
BODYSTRUCTURE output for invalid Content-Types, but since they're invalid
anyway it doesn't really matter what the output is.
Timo Sirainen [Tue, 5 Jun 2018 10:25:30 +0000 (13:25 +0300)]
lib: Add i_stream_nonseekable_try_seek()
This can be used by istreams to more easily implement seeking backwards when
it has to be done by first seeking back to offset 0 and reading from there.
Timo Sirainen [Wed, 15 Nov 2017 13:53:03 +0000 (15:53 +0200)]
lib-imap: imap_envelope_parse() - remove unnecessary data stack frame
imap_envelope_parse_args() isn't using data stack at all, so this
unnecessarily complicates the code. It also prevents using datastack-pool
as the pool parameter.
Timo Sirainen [Fri, 13 Apr 2018 13:14:18 +0000 (16:14 +0300)]
lib-master: If connect() to backend UNIX socket is retried, log a warning
For example if imap-login process needs to retry before it successfully
connects to imap process's socket, a warning is logged. This warning is
important because it means that the imap-login process may have been
sleeping up to 0.5 seconds and causing all the other connections to hang
during it.
It would be better to make this retrying asynchronous, but before spending
time on doing that, lets see if this warning is ever even being logged.
Timo Sirainen [Thu, 3 May 2018 14:06:04 +0000 (17:06 +0300)]
cassandra: Use fallback_consistency on more types of errors
This could allow for example read_consistency=local-quorum with
read_fallback_consistency=quorum, so most of the time the reads are
from local datacenter, but in case it has problems you can switch to
other datacenters.
Timo Sirainen [Tue, 15 May 2018 14:50:27 +0000 (17:50 +0300)]
fs-posix: Strip trailing "/" from filenames
This is mainly because "doveadm fs delete -R" adds it to indicate to the
fs-driver that the whole directory is wanted to be deleted. This change
fixes fs-posix to work with NFS, where otherwise unlink("symlink-to-dir/")
fails with ENOTDIR. Without NFS the same call succeeds.
Timo Sirainen [Thu, 3 May 2018 12:22:09 +0000 (15:22 +0300)]
fs-posix: mkdir missing directory if it's changed by FS_METADATA_WRITE_FNAME
The temp file is created to the initial directory. If the directory is
changed by FS_METADATA_WRITE_FNAME, the new destination directory didn't
necessarily exist. If the link() or rename() fails with ENOENT, try to
mkdir the missing directories.
mdbox: Assume that empty uid maps found during sync are harmless
Instead of failing the sync and causing index rebuild, just skip over
the empty uid maps. Chances are that they these records came from
various plugins that create fake mails.
This was done to call extension record sync handlers, but the previous
commit removes them. Fixes a problem where obsolete cache offsets were
used in some situations:
- Some cache updates are from external transactions and some are from
non-external transactions. This is because cache offset updates are being
added by whatever the parent index transaction is.
- When mail_index_sync_map() is mapping MAIL_INDEX_SYNC_HANDLER_FILE, it
has already synced the map. But it's calling mail_index_sync_record()
for non-external transactions to call expunge handlers and extension
update handlers. It's calling the regular mail_index_sync_record() to do
this work.
- But mail_index_sync_record() is actually still updating the map. So now
mail_index_sync_record() is called for all non-external cache updates,
but not for external cache updates! And since these are somewhat
randomly either external or non-external, the end result is that the
cache offset may be obsolete.