Stephan Bosch [Fri, 27 Jun 2014 14:39:52 +0000 (17:39 +0300)]
imap-url: Fixed handling of ipath-empty syntax (basically empty relative URLs).
This also normalizes Mailbox/ to Mailbox.
Initial indication reported by Coverity.
Phil Carmody [Fri, 27 Jun 2014 13:20:25 +0000 (16:20 +0300)]
lib: rand - force reseeding with known seed from environment
Use DOVECOT_SRAND=12345 as an environmental variable to force seeding
to that number.
The logic behind the logging is that the subsequent calls will almost
certainly be from random_fill_weak() which expects to have been seeded
from a CSPRNG - not a constant! Having this environmental variable set
in a production system that expects CSPRNG seeding should be flagging
diagnostics.
Phil Carmody [Fri, 27 Jun 2014 13:17:50 +0000 (16:17 +0300)]
lib: remove unwanted srand()s from unit tests
We'll get better coverage without them.
Note: this change causes the following test case failure occasionally:
test-istream-concat.c:88: Assert failed: size >= TEST_MAX_BUFFER_SIZE
istream concat random ................................................ : FAILED
test: random seed #1 was 1403027537
Phil Carmody [Fri, 27 Jun 2014 13:17:07 +0000 (16:17 +0300)]
lib-test: use the new srand() tracking helpers to aid debugging
We can only be sure we know the entirity of the stream of numbers returned
by rand if rand_set_seed has been called precisely once, as after that we
can't be sure when it was called a 2nd or further time. However, at least
we can know that that has happened. (Likewise, any calls to srand() will
disturb the flow.)
Most unit test cases should be simple enough that there should be only one
seeding.
Phil Carmody [Fri, 27 Jun 2014 13:16:16 +0000 (16:16 +0300)]
lib: use new srand() wrapper in lib
Of course, multiple seeding calls make it harder to know exactly
what numbers have been generated. But this is better than nothing.
Phil Carmody [Fri, 27 Jun 2014 13:15:24 +0000 (16:15 +0300)]
lib: add rand helper library
Initially, just wrap srand() so that we can find out what the last-used
seed was. In situations where srand() is called only once (via this helper)
this lets us reproduce exactly the same stream of random data again in
order to reproduce rare crashes.
Phil Carmody [Fri, 27 Jun 2014 13:13:37 +0000 (16:13 +0300)]
lib: two quite literally random little cleanups
file-dotlock.c does not use randgen.h, remove the #include
test-buffer.c random() has been used rather than rand()
Phil Carmody [Fri, 27 Jun 2014 13:13:09 +0000 (16:13 +0300)]
lib: make printf_format_fix safer against shadowed %m behaviour
If there's a %m followed by a %n or %m, then the %n or %m won't be seen.
For %m, that's mostly harmless, but for %n it's potentially kaboom.
Timo Sirainen [Thu, 26 Jun 2014 17:46:21 +0000 (20:46 +0300)]
lib: iostream-rawlog now supports TCP target with "tcp:host:port" as the path.
We'll use blocking sockets, so a slow rawlog server causes performance
problems also for Dovecot while it's waiting on rawlog writes.
Timo Sirainen [Thu, 26 Jun 2014 14:50:57 +0000 (17:50 +0300)]
lib-storage: BODYSTRUCTURE parsing failures weren't treated correctly.
We still assumed that the parsing succeeded and assert-crashed later or
maybe returned invalid results. (This could have happened only if there was
a problem reading the mail stream.)
Timo Sirainen [Thu, 26 Jun 2014 14:27:22 +0000 (17:27 +0300)]
dbox: mail_get_special() may have returned MAIL_FETCH_POP3_ORDER allocated from data stack.
Although this seems to have worked for now, it shouldn't have been done.
Timo Sirainen [Fri, 20 Jun 2014 09:18:32 +0000 (12:18 +0300)]
lib: fd_recv() no longer checks for msghdr.msg_controllen
It doesn't work at least in OpenBSD and Tru64, and apparently it shouldn't
really be needed anyway, so don't bother with it. We'll still keep checking
the cmsghdr since that appears to work everywhere now.
Timo Sirainen [Thu, 19 Jun 2014 14:16:24 +0000 (17:16 +0300)]
mbox: istream-tee wasn't being used as expected with the new changes, causing crashes/hangs.
After wondering about this for a while I decided this was the only fully
reliable way of doing this. Although it would have been possible to change
the istream-tee code to support this:
child1 and child2 are tee-istream children:
- i_stream_read(child1)
- i_stream_read(child2)
- i_stream_get_data(child1)
Because reading from the parent istream-tee updates all of its childrens'
buffer, there's no big problem (other than access_counter currently messing
up). But if one of the children weren't a direct child of tee-istream, but
there was a wrapper istream, the wrapper's buffer wouldn't have been updated
by the istream-tee read. So rather than spending time figuring out to fix
the access_counter it's probably better to have it clearly fail as the use
case can't be fully safe anyway.
Timo Sirainen [Thu, 19 Jun 2014 12:50:40 +0000 (15:50 +0300)]
lmtp: Create all proxy DATA streams before reading from them.
I'm not sure if this actually fixes anything or not, but it's still safer
to do it this way.
Timo Sirainen [Thu, 19 Jun 2014 12:15:24 +0000 (15:15 +0300)]
lib: i_stream_read_copy_from_parent() now directly updates the access counter
This fixes a bug in istream-mail where it called i_stream_get_data() after
it and reset the stream's skip/pos.
Timo Sirainen [Thu, 19 Jun 2014 10:52:36 +0000 (13:52 +0300)]
lib: If two istreams share one parent, i_stream_get_data() may have returned corrupted data to another.
This happened only for istreams that used parent's buffer directly instead
of having their own buffer. For now at least we've solved this by truncating
the other stream's buffer so it needs to be read again. Hopefully this is
good enough.
Timo Sirainen [Mon, 16 Jun 2014 16:52:11 +0000 (19:52 +0300)]
login proxy: Added login_source_ips setting.
The setting contains a list of IPs/hosts. The setting may be prefixed with
"?" character to indicate that only those IPs should be used that exist in
the current server (allowing the same config to be shared by multiple
servers).
The IPs are used round robin as the source IP address when proxy creates TCP
connections. This becomes useful when there are a ton of connections from
the proxy to the same destination IP, because TCP ports run out after ~64k
connections.
Phil Carmody [Sat, 14 Jun 2014 08:58:57 +0000 (11:58 +0300)]
trivial variable-non-use fixes
Flagged by coverity. In one, as we're printing an error message, we
can actually put the string to use, which might aid debugging. In
the other, the variable can just be killed.
Phil Carmody [Fri, 13 Jun 2014 13:12:27 +0000 (16:12 +0300)]
fts-lucene: Fix SnowballAnalyzer constructors
Coverity found the uninitialised pointers in the latter constructor (which
is never used - kill it?). In comparing the other constructor, the lack of
strdup() jumped out at me.
In fixing them both I migrated them to actual C++ initialisers, rather than
dumb assignments to uninitialised members. Also migrated to dovecot's i_*
functions. Also fixed indentation for the 3 functions touched.
Timo Sirainen [Fri, 13 Jun 2014 12:14:44 +0000 (15:14 +0300)]
Added several asserts to make sure duplicates aren't inserted into hash table.
The previous commit hopefully fixed the problem causing auth and login
processes to sometimes die with "key not found from hash" error, but if not
maybe one of these will catch it.
Timo Sirainen [Fri, 13 Jun 2014 12:13:26 +0000 (15:13 +0300)]
lib-master: Fixed caching settings where both local_name and local_ip was specified.
Since cache_find() didn't use local_ip for a lookup when local_name existed,
cache_add() shouldn't add both of them either, otherwise it could be
inserting duplicate values to the cache hash and cause crashes.
Timo Sirainen [Thu, 12 Jun 2014 23:54:21 +0000 (02:54 +0300)]
imap, pop3: Remove the client from clients-list at the very end of the destroy function.
Especially with imap code the process title could have been refreshed too
early.
Timo Sirainen [Thu, 12 Jun 2014 22:30:14 +0000 (01:30 +0300)]
lib-storage: Fixed parsing corrupted mailbox list index header.
Duplicate IDs should have caused an error instead of being silently ignored.
Found by Coverity
Timo Sirainen [Thu, 12 Jun 2014 22:20:25 +0000 (01:20 +0300)]
lib-otp: OTP_MAX_WORD_LEN wasn't actually enforced, any word lengths could have been used.
Doesn't look like this could have caused any real problems.
Found by Coverity
Timo Sirainen [Thu, 12 Jun 2014 22:11:24 +0000 (01:11 +0300)]
fts: Improved doveadm fts dump for corrupted expunge log
Although we may still be trying to allocate up to 2 GB of memory, but at
least no more than that now.
Found by Coverity
Timo Sirainen [Thu, 12 Jun 2014 22:02:48 +0000 (01:02 +0300)]
lib: Fixed file_dotlock_replace(flags=DOTLOCK_REPLACE_FLAG_VERIFY_OWNER|DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD)
The verification check failed because fd was already set to -1 by that time.
Found by Coverity
Timo Sirainen [Thu, 12 Jun 2014 21:51:44 +0000 (00:51 +0300)]
imapc: Avoid crashing if server happens to send invalid resp-text-codes.
If [KEY VALUE] is missing the VALUE, just set it to "" instead of NULL.
Found by Coverity
Timo Sirainen [Thu, 12 Jun 2014 21:30:27 +0000 (00:30 +0300)]
auth: Invalid userdb passwd-file and userdb templates may have caused crashes.
Using just "key" parameter instead of "key=value" usually worked, but for
some keys the code assumed that there was a value and it dereferenced NULL.
We'll solve this by just using value="" instead of value=NULL.
Found by Coverity
Timo Sirainen [Thu, 12 Jun 2014 21:09:23 +0000 (00:09 +0300)]
lib: Changed net_geterror() to return errno instead of -1 if getsockopt() fails.
None of the callers were actually checking for the -1 error value but
instead just passing it to strerror(). Since this error should just about
never happen it's better to just return a usable return value than try to
remember to handle errors that can't normally even happen.
Found by Coverity
Timo Sirainen [Thu, 12 Jun 2014 20:16:40 +0000 (23:16 +0300)]
configure: Don't actually run the test to see if inotify works.
It's definitely no longer needed in modern Linux systems and the test itself
can also unintentionally fail sometimes.
Timo Sirainen [Thu, 12 Jun 2014 09:51:34 +0000 (12:51 +0300)]
lib: Changed hash_table_remove() "key not found" panic to be in a macro itself.
This makes it much easier to find out where such crashes are coming from.
Since this breaks the ABI in such a many places the ABI version number was
increased immediately..
Phil Carmody [Mon, 9 Jun 2014 20:02:52 +0000 (23:02 +0300)]
lib: fix numpack overflow checking
As on broken input, bits may grow without limit, so << bits becomes
Undefined Behaviour. Add a simple check to the while loop to prevent
this.
Also, the (presumably) final byte adds something to the bit length,
so include that in the tally. If we didn't get to a final byte due
to the above while() condition, then this extra addition does no harm
Now we can precisely check for overflow conditions. Note that 64 bits
is perfectly OK, only 65+ is an overflow.
Note - no longer moving *p if there was a decode error.
Expand the test suite to check for overflow cases. Also checked for
short-input cases too, while I was there.
Phil Carmody [Mon, 9 Jun 2014 20:02:52 +0000 (23:02 +0300)]
lib-test: test_assert helper for loops
If you're repeatedly testing the same expression in a loop, it's
good to know where you are in the loop. Add an additional parameter
for these cases.
Phil Carmody [Mon, 9 Jun 2014 20:02:52 +0000 (23:02 +0300)]
lib: bit twiddles
bits_requiredXX() gives the number of bits required to store an unsigned
integer. Here, XX is 8, 16, 32, 64, reperesenting the size of the operand.
It belongs in the same file as nearest_power(), which makes most sense
in a separate bit twiddles file. Universal enough to stay in lib.h by
inclusion.
Phil Carmody [Mon, 9 Jun 2014 19:59:59 +0000 (22:59 +0300)]
lib: Fix MEM_ALIGN to cope with huge allocations
Attempting to allocate 2^32+1 bytes will look like it succeeds, as MEM_ALIGN
will set alloc_size = 8. The caller will then think it's got 4 gig to play
with.
e.g. t_malloc0 will wipe vast areas of memory before segfaulting, which might
include useful information we'd like in a corefile.
Timo Sirainen [Mon, 9 Jun 2014 19:53:16 +0000 (22:53 +0300)]
lib-index: modseq -> {log file, offset} lookup often ignored dovecot.index.log.2
This caused the code to think that the modseq was too old and fall back into
slower sync.
So this change should fix the dsync "Modseq .. nom longer in transaction
log" warnings as well as improve IMAP QRESYNC efficiency.
Timo Sirainen [Mon, 9 Jun 2014 15:15:51 +0000 (18:15 +0300)]
lib: Added some kind of a unit test for hash table.
Just try out some insert+deletes randomly. Mainly I wrote this to check if
there is some obvious problem, but looks like not.
Timo Sirainen [Mon, 9 Jun 2014 12:11:50 +0000 (15:11 +0300)]
lib-ssl-iostream: Implement get_used_size() method.
Previously we were always returning that we didn't have anything buffered,
which could have caused huge memory usage (or malloc failures) with its
users (e.g. dsync).