From: Timo Sirainen Date: Wed, 18 May 2016 11:52:03 +0000 (+0300) Subject: lib-mail: Added asserts to message_get_*_size() X-Git-Tag: 2.3.0.rc1~3699 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f75daca243aed043737496b2bef9892d87659fc;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: Added asserts to message_get_*_size() --- diff --git a/src/lib-mail/message-size.c b/src/lib-mail/message-size.c index 61e0a5432d..a01bc33c59 100644 --- a/src/lib-mail/message-size.c +++ b/src/lib-mail/message-size.c @@ -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;