]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: Added asserts to message_get_*_size()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 18 May 2016 11:52:03 +0000 (14:52 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 18 May 2016 16:56:45 +0000 (19:56 +0300)
src/lib-mail/message-size.c

index 61e0a5432dad71820e552cff85a0b07536dba194..a01bc33c590e7e3787a7e0b57853958721d193f3 100644 (file)
@@ -16,7 +16,7 @@ int message_get_header_size(struct istream *input, struct message_size *hdr,
        *has_nuls_r = FALSE;
 
        missing_cr_count = 0; startpos = 0;
-       while (i_stream_read_bytes(input, &msg, &size, startpos + 1) > 0) {
+       while ((ret = i_stream_read_bytes(input, &msg, &size, startpos + 1)) > 0) {
                for (i = startpos; i < size; i++) {
                        if (msg[i] != '\n') {
                                if (msg[i] == '\0')
@@ -54,6 +54,8 @@ int message_get_header_size(struct istream *input, struct message_size *hdr,
 
                hdr->physical_size += i - startpos;
        }
+       i_assert(ret == -1 || ret > 0);
+
        ret = input->stream_errno != 0 ? -1 : 0;
        i_stream_skip(input, startpos);
        hdr->physical_size += startpos;
@@ -74,8 +76,10 @@ int message_get_body_size(struct istream *input, struct message_size *body,
        *has_nuls_r = FALSE;
 
        missing_cr_count = 0;
-       if ((ret = i_stream_read_more(input, &msg, &size)) <= 0)
+       if ((ret = i_stream_read_more(input, &msg, &size)) <= 0) {
+               i_assert(ret == -1);
                return ret < 0 && input->stream_errno != 0 ? -1 : 0;
+       }
 
        if (msg[0] == '\n')
                missing_cr_count++;
@@ -102,7 +106,8 @@ int message_get_body_size(struct istream *input, struct message_size *body,
                /* leave the last character, it may be \r */
                i_stream_skip(input, i - 1);
                body->physical_size += i - 1;
-       } while (i_stream_read_bytes(input, &msg, &size, 2) > 0);
+       } while ((ret = i_stream_read_bytes(input, &msg, &size, 2)) > 0);
+       i_assert(ret == -1);
 
        ret = input->stream_errno != 0 ? -1 : 0;