* mailbox/mbx_imap.c(imap_message_readline imap_body_readline):
The buffer was not null terminated if no newline was found.
Showing
2 changed files
with
22 additions
and
9 deletions
1 | 2001-10-14 Alain Magloire | 1 | 2001-10-14 Alain Magloire |
2 | 2 | ||
3 | * mailbox/mbx_imap.c(imap_message_readline imap_body_readline): | ||
4 | The buffer was not null terminated if no newline was found. | ||
5 | |||
6 | 2001-10-14 Alain Magloire | ||
7 | |||
3 | The code for IMAP, is a pain, the rewrite should clean all those | 8 | The code for IMAP, is a pain, the rewrite should clean all those |
4 | hacks. Something to remember for the mailbox2 is to do some | 9 | hacks. Something to remember for the mailbox2 is to do some |
5 | smart caching, the current buffered stream is not good enough. | 10 | smart caching, the current buffered stream is not good enough. | ... | ... |
... | @@ -955,7 +955,6 @@ imap_message_readline (stream_t stream, char *buffer, size_t buflen, | ... | @@ -955,7 +955,6 @@ imap_message_readline (stream_t stream, char *buffer, size_t buflen, |
955 | { | 955 | { |
956 | message_t msg = stream_get_owner (stream); | 956 | message_t msg = stream_get_owner (stream); |
957 | msg_imap_t msg_imap = message_get_owner (msg); | 957 | msg_imap_t msg_imap = message_get_owner (msg); |
958 | m_imap_t m_imap = msg_imap->m_imap; | ||
959 | size_t lines = msg_imap->message_lines; | 958 | size_t lines = msg_imap->message_lines; |
960 | int status; | 959 | int status; |
961 | size_t len = 0; | 960 | size_t len = 0; |
... | @@ -973,14 +972,15 @@ imap_message_readline (stream_t stream, char *buffer, size_t buflen, | ... | @@ -973,14 +972,15 @@ imap_message_readline (stream_t stream, char *buffer, size_t buflen, |
973 | if (nl) | 972 | if (nl) |
974 | { | 973 | { |
975 | nl++; | 974 | nl++; |
976 | *nl = '\0'; | ||
977 | msg_imap->message_lines = lines + 1; | 975 | msg_imap->message_lines = lines + 1; |
978 | } | 976 | } |
979 | else | 977 | else |
980 | nl = buffer + len; | 978 | nl = buffer + len; |
979 | len = nl - buffer; | ||
980 | *nl = '\0'; | ||
981 | } | 981 | } |
982 | if (plen) | 982 | if (plen) |
983 | *plen = nl - buffer; | 983 | *plen = len; |
984 | return status; | 984 | return status; |
985 | } | 985 | } |
986 | 986 | ||
... | @@ -1744,15 +1744,18 @@ imap_body_readline (stream_t stream, char *buffer, size_t buflen, off_t offset, | ... | @@ -1744,15 +1744,18 @@ imap_body_readline (stream_t stream, char *buffer, size_t buflen, off_t offset, |
1744 | { | 1744 | { |
1745 | message_t msg = stream_get_owner (stream); | 1745 | message_t msg = stream_get_owner (stream); |
1746 | msg_imap_t msg_imap = message_get_owner (msg); | 1746 | msg_imap_t msg_imap = message_get_owner (msg); |
1747 | m_imap_t m_imap = msg_imap->m_imap; | 1747 | size_t blines = msg_imap->body_lines; |
1748 | size_t lines = msg_imap->body_lines; | 1748 | size_t bsize = msg_imap->body_size; |
1749 | int status; | 1749 | int status; |
1750 | size_t len = 0; | 1750 | size_t len = 0; |
1751 | char *nl = buffer; | 1751 | char *nl = buffer; |
1752 | 1752 | ||
1753 | /* Start over. */ | 1753 | /* Start over. */ |
1754 | if (offset == 0) | 1754 | if (offset == 0) |
1755 | lines = 0; | 1755 | { |
1756 | blines = 0; | ||
1757 | bsize = 0; | ||
1758 | } | ||
1756 | 1759 | ||
1757 | buflen--; /* for the NULL. */ | 1760 | buflen--; /* for the NULL. */ |
1758 | status = imap_body_read (stream, buffer, buflen, offset, &len); | 1761 | status = imap_body_read (stream, buffer, buflen, offset, &len); |
... | @@ -1762,14 +1765,16 @@ imap_body_readline (stream_t stream, char *buffer, size_t buflen, off_t offset, | ... | @@ -1762,14 +1765,16 @@ imap_body_readline (stream_t stream, char *buffer, size_t buflen, off_t offset, |
1762 | if (nl) | 1765 | if (nl) |
1763 | { | 1766 | { |
1764 | nl++; | 1767 | nl++; |
1765 | *nl = '\0'; | 1768 | msg_imap->body_lines = blines + 1; |
1766 | msg_imap->body_lines = lines + 1; | ||
1767 | } | 1769 | } |
1768 | else | 1770 | else |
1769 | nl = buffer + len; | 1771 | nl = buffer + len; |
1772 | len = nl - buffer; | ||
1773 | msg_imap->body_size = bsize + len; | ||
1774 | *nl = '\0'; | ||
1770 | } | 1775 | } |
1771 | if (plen) | 1776 | if (plen) |
1772 | *plen = nl - buffer; | 1777 | *plen = len; |
1773 | return status; | 1778 | return status; |
1774 | } | 1779 | } |
1775 | 1780 | ||
... | @@ -1802,7 +1807,10 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset, | ... | @@ -1802,7 +1807,10 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset, |
1802 | 1807 | ||
1803 | /* Start over. */ | 1808 | /* Start over. */ |
1804 | if (offset == 0) | 1809 | if (offset == 0) |
1810 | { | ||
1805 | msg_imap->body_lines = 0; | 1811 | msg_imap->body_lines = 0; |
1812 | msg_imap->body_size = 0; | ||
1813 | } | ||
1806 | 1814 | ||
1807 | /* Select first. */ | 1815 | /* Select first. */ |
1808 | if (f_imap->state == IMAP_NO_STATE) | 1816 | if (f_imap->state == IMAP_NO_STATE) | ... | ... |
-
Please register or sign in to post a comment