From: Timo Sirainen Date: Fri, 20 Jan 2017 15:34:50 +0000 (+0200) Subject: lib-mail: istream-header-filter - Fix header read() when max_buffer_size=0 X-Git-Tag: 2.3.0.rc1~654 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fdf15b2c4fd47078108f556a58c6b9f365449f9e;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: istream-header-filter - Fix header read() when max_buffer_size=0 If the buffer was too small to read anything into it, read_header() returned -2, but then it continued reading the header as if it was the body already. This should instead be an error situation - max buffer size just shouldn't be 0 at this point. This was originally changed in a72355fef49c512c13b7d8c3e07f4f76ebd57a10 as some kind of a workaround, but since then we implemented support for reading a mixed header/body in c2afdbf963d0564a542d71ca784deb0c2f7776d0. --- diff --git a/src/lib-mail/istream-header-filter.c b/src/lib-mail/istream-header-filter.c index a4ed1c3b50..5d209d48c8 100644 --- a/src/lib-mail/istream-header-filter.c +++ b/src/lib-mail/istream-header-filter.c @@ -187,8 +187,10 @@ static ssize_t read_header(struct header_filter_istream *mstream) } max_buffer_size = i_stream_get_max_buffer_size(&mstream->istream.istream); - if (mstream->hdr_buf->used >= max_buffer_size) + if (mstream->hdr_buf->used >= max_buffer_size) { + i_assert(max_buffer_size > 0); return -2; + } while ((hdr_ret = message_parse_header_next(mstream->hdr_ctx, &hdr)) > 0) { @@ -441,11 +443,8 @@ static ssize_t i_stream_header_filter_read(struct istream_private *stream) } if (!mstream->header_read || - stream->istream.v_offset < mstream->header_size.virtual_size) { - ret = read_header(mstream); - if (ret != -2 || stream->pos != stream->skip) - return ret; - } + stream->istream.v_offset < mstream->header_size.virtual_size) + return read_header(mstream); if (mstream->hide_body) { stream->istream.eof = TRUE;