Stephan Bosch [Wed, 20 Feb 2019 21:19:03 +0000 (22:19 +0100)]
lib-http: http-client-connection - Create function for obtaining client settings reliably.
This fixes and prevents segfaults occurring when settings are needed while the
connection is detached. In that case, the shared client context settings need
to be used rather than the client settings. Before, the attachment of a peer was
assumed for obtaining the settings when it actually could be absent in rare
cases, causing a NULL dereference.
Stephan Bosch [Sun, 9 Dec 2018 20:14:29 +0000 (21:14 +0100)]
lib-oauth2: Fix assert panic occurring while skipping ignored object and array fields.
Fixed by using json_parse_skip(), rather than json_parse_skip_next(). The latter
is not suitable for skipping a value that is already partially parsed by
json_parse_next().
Stephan Bosch [Sun, 9 Dec 2018 20:08:53 +0000 (21:08 +0100)]
lib-oauth2: Fix asynchronous parsing of JSON response payload.
The problem was caused by the fact that req->field_name was reset in the
beginning of oauth2_parse_json(), which is continuously called when more payload
can be read from the input stream. This leads to corruption of the parser state
machine each time parsing is continued.
To fix this issue, the field_name is now reset only when the parsing commences.
Stephan Bosch [Sun, 9 Dec 2018 19:27:10 +0000 (20:27 +0100)]
lib: json-parser: Add unit test on skipping various object member fields.
This both tests skipping fields based on their member key and based on their
value types; i.e., after calling json_parse_next() for the object member value.
Stephan Bosch [Sun, 9 Dec 2018 19:24:28 +0000 (20:24 +0100)]
lib: json-parser: Add support for skipping a value that is already partially parsed.
Adds json_parse_skip(), which skips the remainder of the value parsed earlier by
json_parse_next(). This is needed when values need to be skipped by their value
type rather than their object member key.
Aki Tuomi [Wed, 27 Feb 2019 13:25:06 +0000 (15:25 +0200)]
lib-storage: pop3c - Copy SSL settings correctly
When attempting to use pop3c with immediate SSL, it would
crash due to invalid memory access during connection setup.
Also the SSL mode is not copied so SSL handshake is not attempted
at later stage.
Aki Tuomi [Mon, 25 Feb 2019 15:44:09 +0000 (17:44 +0200)]
lib-ssl-iostream: Call ssl_iostream_check_cert_validity as default
Unless callback is specified, call ssl_iostream_check_cert_validity
instead of ssl_iostream_cert_match_name to make sure we perform
same checks consistently.
Stephan Bosch [Thu, 7 Feb 2019 01:37:27 +0000 (02:37 +0100)]
lib-smtp: smtp-client-command - Avoid calling the callback for the DATA command during submission.
This causes a race condition in which the command object is already freed when
it is returned from smtp_client_command_data_submit(). This scenario occurs when
reading data for the first BDAT command fails.
Stephan Bosch [Sun, 9 Dec 2018 11:13:59 +0000 (12:13 +0100)]
lib-smtp: command: Move main loop from sub-function to smtp_client_command_send_more() itself.
This reduces code indent in smtp_client_command_do_send_more() (the
sub-function) and it turns the inifite for loop into a nice conditional
while loop.
Stephan Bosch [Sun, 11 Nov 2018 22:32:15 +0000 (23:32 +0100)]
lib-smtp: test-smtp-client-errors: Test early DATA command success and error replies.
Early success for the DATA command is treated as a protocol error, while early
failure is allowed. Both situations are tested in a new scenario for the
test-smtp-client-errors unit test.
Stephan Bosch [Sun, 11 Nov 2018 19:30:25 +0000 (20:30 +0100)]
lib-smtp: test-smtp-client-errors: Add test scenario for premature success replies.
Such replies are sent immediately along with the reply of the previous command.
So, the reply is sent before the corresponding command is even submitted. This
tests whether the client handles this erroneous situation correctly.
Stephan Bosch [Wed, 15 Aug 2018 16:29:11 +0000 (18:29 +0200)]
lib-smtp: client: Allow receiving replies before command data stream is sent completely.
This avoids unnecessary problems with servers that reply somewhat early to DATA
and BDAT commands. For one, early failure replies are now handled properly.
Also, race conditions at the client between sending the closing CRLF.CRLF and
receiving the DATA reply are no longer causing problems.
Stephan Bosch [Sat, 8 Sep 2018 18:54:54 +0000 (20:54 +0200)]
lib-smtp: client: BDAT command: Make sure the message contains CRLF consistently.
Before, only messages sent using DATA command guaranteed consistent CRLF,
because these are sent using o_stream_dot(), which does that internally. For the
BDAT command, the message was sent as-is, which is not always accepted by MTAs.
Stephan Bosch [Fri, 26 Oct 2018 10:15:45 +0000 (12:15 +0200)]
lib-smtp: client: BDAT command: Ensure data stream max buffer size is appropriate when stream size is unknown.
When stream size is unknown, the chunk size are determined by what can be
buffered in the data input stream immediately. If it's maximum buffer size is
(much) smaller than the maximum chunk size, the maximum chunk size is never
achieved.
Stephan Bosch [Fri, 26 Oct 2018 14:17:06 +0000 (16:17 +0200)]
lib-smtp: server: Fix forwarding a multi-line reply.
A multi-line reply had the '-' on the first line stripped upon sending, which
makes clients see two separate responses rather than just one. This was caused
by the fact that forwarded replies had the last_line field not set properly,
in which case the '-' was substituted on the first line, rather than the last.
The fix makes a forwarded reply indistinguishable from a normally created reply
by also allowing for amending the reply with additional lines using
smtp_server_reply_add_text().
Stephan Bosch [Fri, 7 Dec 2018 21:38:19 +0000 (22:38 +0100)]
lib-http: client: Fix panic occurring at connection failure.
In http_client_peer_connection_failed_pool(), all linked queues are notified
about the connection failure through http_client_queue_connection_failure().
That function can internally link and unlink peers to the queue, including the
calling one. This means that the peer->queues array can be modified while it is
iterated in the array_foreach() loop. The problem is fixed by making a local
copy of the peer->queues array.
Aki Tuomi [Mon, 23 Jul 2018 09:40:15 +0000 (12:40 +0300)]
lib-ssl-iostream: Always fall back to default CAs for client contexts
When creating a client context, we always try to load the default
CA, if no CA settings have been provided. This makes it also possible
to allow invalid certs without specifying ssl_client_ca settings,
and also makes dovecot trust system store by default for outgoing
connections.
Timo Sirainen [Mon, 25 Feb 2019 18:55:03 +0000 (20:55 +0200)]
fs-posix: fs_read_stream() - Don't close file's fd
This is especially important with newly created files, because they may
still be accessed after reading. The next file access attempt after
fs_read_stream() might cause the file to be recreated and crash.
Timo Sirainen [Tue, 19 Feb 2019 08:17:45 +0000 (10:17 +0200)]
lib: istream-seekable - Change stream to be blocking=TRUE after reaching EOF
After EOF is reached, the stream is now fully read into file or memory.
read()s can no longer return 0, so blocking=TRUE can be used.
Some callers were reusing the seekable stream in places that required
blocking=TRUE.
Fixes at least with imapsieve vnd.dovecot report extension:
Panic: file ostream.c: line 427 (o_stream_nsend_istream): assertion failed: (instream->blocking)