]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: istream-header-filter - Fix header read() when max_buffer_size=0
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 20 Jan 2017 15:34:50 +0000 (17:34 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 1 Nov 2017 11:45:51 +0000 (13:45 +0200)
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.

src/lib-mail/istream-header-filter.c

index a4ed1c3b50f15f09325f0318261523904f2fcbc4..5d209d48c8932e6a0f47c755699f04bc4f9bb8bb 100644 (file)
@@ -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;