]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
istream-attachment-extractor: Fixed handling attachment as the message body without...
authorTimo Sirainen <tss@iki.fi>
Sun, 16 Jun 2013 18:08:40 +0000 (21:08 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 16 Jun 2013 18:08:40 +0000 (21:08 +0300)
Don't crash at the end after parsing the base64 data.

src/lib-mail/istream-attachment-extractor.c

index 857234726b9d84e3b7951175aff7a64d7a27a7c1..4abab586d6c105fc8b53d4399e6857937eaee374 100644 (file)
@@ -524,6 +524,7 @@ static int
 astream_end_of_part(struct attachment_istream *astream)
 {
        struct attachment_istream_part *part = &astream->part;
+       size_t old_size;
        int ret = 0;
 
        /* MIME part changed. we're now parsing the end of a boundary,
@@ -540,8 +541,15 @@ astream_end_of_part(struct attachment_istream *astream)
                }
                break;
        case MAIL_ATTACHMENT_STATE_YES:
+               old_size = astream->istream.pos - astream->istream.skip;
                if (astream_part_finish(astream) < 0)
                        ret = -1;
+               else {
+                       /* finished base64 may have added a few more trailing
+                          bytes to the stream */
+                       ret = astream->istream.pos -
+                               astream->istream.skip - old_size;
+               }
                break;
        }
        part->state = MAIL_ATTACHMENT_STATE_NO;