]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: istream-header-filter - Avoid unsigned overflow in last_offset calculation
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 20 Aug 2020 07:55:36 +0000 (10:55 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 11 Sep 2020 07:07:20 +0000 (07:07 +0000)
Unsigned integer overflow occurs when size is 0.

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

index cc8eef8128d23bedde579534e5446328f2b16796..479a4bb219c626585ab570f3203db0f1cf9aadd6 100644 (file)
@@ -393,11 +393,15 @@ handle_end_body_with_lf(struct header_filter_istream *mstream, ssize_t ret)
 {
        struct istream_private *stream = &mstream->istream;
        const unsigned char *data;
-       size_t size, last_offset;
+       size_t size;
+       uoff_t last_offset;
        bool last_lf;
 
        data = i_stream_get_data(stream->parent, &size);
-       last_offset = stream->parent->v_offset + size-1;
+       if (stream->parent->v_offset + size == 0 && size == 0)
+               last_offset = (uoff_t)-1;
+       else
+               last_offset = stream->parent->v_offset + size - 1;
 
        if (mstream->last_lf_offset == last_offset)
                last_lf = TRUE;