Skip to content

Commit

Permalink
lib-mail: istream-header-filter - Check errors reading header
Browse files Browse the repository at this point in the history
This probably doesn't affect the results much, since the stream_errno is set
anyway. But it's better to abort early, just in case the broken state might
end up asserting later.
  • Loading branch information
sirainen committed May 11, 2016
1 parent 9700009 commit a3cdcdd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib-mail/istream-header-filter.c
Expand Up @@ -446,12 +446,12 @@ i_stream_header_filter_seek_to_header(struct header_filter_istream *mstream,
mstream->seen_eoh = FALSE;
}

static void skip_header(struct header_filter_istream *mstream)
static int skip_header(struct header_filter_istream *mstream)
{
size_t pos;

if (mstream->header_read)
return;
return 0;

if (mstream->istream.access_counter !=
mstream->istream.parent->real_stream->access_counter) {
Expand All @@ -464,6 +464,7 @@ static void skip_header(struct header_filter_istream *mstream)
pos = i_stream_get_data_size(&mstream->istream.istream);
i_stream_skip(&mstream->istream.istream, pos);
}
return mstream->istream.istream.stream_errno != 0 ? -1 : 0;
}

static void
Expand Down Expand Up @@ -502,7 +503,8 @@ static void i_stream_header_filter_seek(struct istream_private *stream,
/* if we haven't parsed the whole header yet, we don't know if we
want to seek inside header or body. so make sure we've parsed the
header. */
skip_header(mstream);
if (skip_header(mstream) < 0)
return;
stream_reset_to(mstream, v_offset);

if (v_offset < mstream->header_size.virtual_size) {
Expand Down Expand Up @@ -542,7 +544,8 @@ i_stream_header_filter_stat(struct istream_private *stream, bool exact)

/* fix the filtered header size */
old_offset = stream->istream.v_offset;
skip_header(mstream);
if (skip_header(mstream) < 0)
return -1;

stream->statbuf.st_size -=
(off_t)mstream->header_size.physical_size -
Expand Down

0 comments on commit a3cdcdd

Please sign in to comment.