Paul Howarth [Mon, 2 Jul 2018 10:52:14 +0000 (11:52 +0100)]
lib-compression: Fix assert-crash in test suite on 32bit systems
Fix compilation warnings in test-compression.c due to mismatches
between size_t and uoff_t, which then manifests in assert-crashes
running the test suite on 32bit systems.
Timo Sirainen [Fri, 6 Jul 2018 08:25:07 +0000 (11:25 +0300)]
lib-ssl-iostream: Shutdown connection cleanly whenever i/ostream is destroyed
Do this while both istream and ostream still exist. Fixes crash where
openssl_iostream_destroy() attempts to flush the shutdown, but ssl_input
is NULL and it crashes.
Timo Sirainen [Mon, 18 Jun 2018 13:19:55 +0000 (16:19 +0300)]
lib: If log write returns EAGAIN, use poll() instead of ioloop for waiting
As explained in 861d40b9aebabccae7d48e49a18cbc631ab1fefe commit message,
ioloop can call various callbacks and it can also recurse back to error
logging. Using poll() directly is safer.
Timo Sirainen [Mon, 18 Jun 2018 13:07:30 +0000 (16:07 +0300)]
lib: Revert earlier "log write is blocking" handling change
1) It was buggy, because it set O_NONBLOCK rather than removing it.
2) fd flags are shared across all the processes using the fd. We can't
reliably implement the process title update, because some processes are
blocking on the log write() before they change the process title.
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.
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.
Phil Carmody [Thu, 11 Jan 2018 13:35:42 +0000 (15:35 +0200)]
global - migrate more complicated strncmp expressions to str_begins
Simplify a bunch of verbose var=strlen(); strncmp(,,var) calls.
Fortunately, all of these examples use the length variable, so no
"unused value" warnings occur.
Phil Carmody [Thu, 2 Feb 2017 12:27:58 +0000 (14:27 +0200)]
lib: strfuncs - string match length and prefix checking helpers
strncmp(input, "literal", 7) is an idiom used everywhere, but leaves
room for human error in calculating the length.
strncmp(input, "literal", strlen("literal")) is an idiom also used
everywhere, but is both verbose and might be inefficient on some
legacy or ultralightweight compilers.
The old techniques are presumed to be optimal code-wise, but are
verbose (and, containing redundancy, they leave room for human error),
so make the macro fall back onto this operation, simply avoiding the
redundancy/verbosity.
The macro expansion does not multiply evaluate any of its parameters,
so should be safe even in the strangest of situations.
This patch fixes a regression introduced in 638600575ee95f2513c683ef09cb188f76eacd22 where mail_fsync=always would
not be honoured, leading to fatal "nfs flush requires mail_fsync=always"
errors.
Stephan Bosch [Fri, 18 May 2018 13:56:15 +0000 (15:56 +0200)]
lib-http: client: Drop the ioloop switch callback before freeing the global client context.
This removes the possibility of recursion when the client context object somehow
triggers an ioloop switch (e.g., when debug logging starts blocking at that
inopportune moment).
Timo Sirainen [Fri, 18 May 2018 09:47:02 +0000 (12:47 +0300)]
lib: Fix potential crashes when writing to log fails with EAGAIN
The ioloop may nowadays call ioloop context switch callbacks. Since log
writing can happen just about anywhere, the callbacks may be confused
and cause crashes or other weird behavior.
Even if the callbacks aren't called, all the extra code in ioloop can cause
potential problems. Especially any error logging in it wouldn't work properly
since it would just recurse back. So replace the ioloop code with just setting
the log fd to be blocking until the write succeeds.
This commit also removes comments about writes to a blocking terminal fd
causing EAGAINs. This seems unlikely. Probably I was just somehow
confused when originally seeing it and writing the code. If it actually
does happen now, it's still not breaking anything, but it could get into
a busy-loop of write()s constantly returning EAGAIN until they succeed.
Timo Sirainen [Mon, 12 Mar 2018 11:58:02 +0000 (13:58 +0200)]
lib-ssl-iostream: Fix potential crash if istream is destroyed before ostream
This happened if o_stream_destroy() triggered flush, which attempted to read
from the ssl_io->ssl_input. If the istream-ssl was already destroyed, it was
NULL and that caused a crash.
Timo Sirainen [Tue, 5 Jun 2018 11:22:08 +0000 (14:22 +0300)]
lib-compression: deflate ostream - Use Z_FINISH on final flush
Nowadays we have o_stream_finish(), so we can differentiate between
intermediate flush and final flush. Using this allows istream-zlib to
cleanly see that the stream ends.
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.
Stephan Bosch [Fri, 18 May 2018 08:24:46 +0000 (10:24 +0200)]
lib-smtp: client: Fix assertion panic occurring when DATA dot stream cannot be finished immediately.
If o_stream_finish() returns 0, o_stream_send_istream() would be called again
later which causes the panic. Instead, it should only call o_stream_finish() or
o_stream_flush() again to finish the last bit of the output.
Panic was:
Panic: file ostream.c: line 394 (o_stream_send_istream): assertion failed: (!_outstream->finished)
Stephan Bosch [Mon, 14 May 2018 21:56:21 +0000 (23:56 +0200)]
lmtp: Fix segfault occurring when a user turns out to be over quota at DATA transfer.
The LMTP recipient context was not updated with the final recipient address when
the RCPT command was accepted. This left a dangling struct smtp_address pointer
which triggered the segfault when used.
Bill Cole [Mon, 26 Mar 2018 04:52:06 +0000 (00:52 -0400)]
Fix arc4random build checks
The configure script checks for arc4random() but the actual code uses
arc4random_buf(). This breaks for FreeBSD <8.0 and MacOS X <10.7, which
have the former but not the latter. This change (and an autoreconf run)
solves the problem at the cost of not using the available ARC4
implementation.
Stephan Bosch [Wed, 23 May 2018 13:54:53 +0000 (15:54 +0200)]
lib-smtp: server: Fix the enforcement of the maximum DATA command message size.
The global setting from the server object was used, rather than the
per-connection setting. The latter is usually the one that is properly set,
while the global server setting is left at zero. For LMTP this meant that the
40 Mb implicit limit was still in force.