Skip to content

Commit

Permalink
lib-sieve: util: edit-mail: istream: Fix bug in calculation of stream…
Browse files Browse the repository at this point in the history
… position.

This caused an assert panic when the application or child stream did not skip
all buffered data immediately. This was reproducible only when the message input
stream consisted of a concatenation of smaller streams, which is used in LMTP to
prepend a few headers.

The panic was:

Panic: file istream.c: line 329 (i_stream_read_memarea): assertion failed: ((size_t)ret+old_size == _stream->pos - _stream->skip)
  • Loading branch information
stephanbosch committed Mar 5, 2018
1 parent 26828ca commit 9327b55
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/lib-sieve/util/edit-mail.c
Expand Up @@ -1749,13 +1749,10 @@ static ssize_t merge_from_parent
/* Determine where we are appending more data to the stream */
append_v_offset = v_offset + (stream->pos - stream->skip);

if (parent_buffer) {
if (v_offset >= copy_v_offset) {
/* Parent buffer used */
stream->pos -= stream->skip;
stream->skip = 0;
cur_pos = stream->pos;
if (v_offset > copy_v_offset)
parent_v_offset += (v_offset - copy_v_offset);
cur_pos = (stream->pos - stream->skip);
parent_v_offset += (v_offset - copy_v_offset);
} else {
cur_pos = 0;
i_assert(append_v_offset >= copy_v_offset);
Expand Down Expand Up @@ -1818,12 +1815,8 @@ static ssize_t merge_from_parent
}
} else {
/* Just passing buffers from parent; no copying */
if (parent_buffer) {
ret = (pos > stream->pos ? (ssize_t)(pos - stream->pos) :
(ret == 0 ? 0 : -1));
} else {
ret = (pos > 0 ? (ssize_t)pos : (ret == 0 ? 0 : -1));
}
ret = (pos > cur_pos ? (ssize_t)(pos - cur_pos) :
(ret == 0 ? 0 : -1));
stream->buffer = data;
stream->pos = pos;
stream->skip = 0;
Expand Down

0 comments on commit 9327b55

Please sign in to comment.