summaryrefslogtreecommitdiff
path: root/mail/dbmail/files/patch-0004-prevent-assertion-in-p_string_erase
blob: dcef534961966e14ae4555dbbf2490bbc341170a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From b6f28ffa54e6533fd0d8676248d0c9bc6d4bd859 Mon Sep 17 00:00:00 2001
From: Paul J Stevens <p.stevens@lukkien.com>
Date: Sun, 10 Jan 2016 20:01:31 +0100
Subject: [PATCH 04/33] prevent assertion in p_string_erase

---
 src/dm_imapsession.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git src/dm_imapsession.c src/dm_imapsession.c
index dbf1834..67eae60 100644
--- src/dm_imapsession.c
+++ src/dm_imapsession.c
@@ -870,19 +870,20 @@ static void _imap_send_part(ImapSession *self, GMimeObject *part, body_fetch *bo
 	} else {
 		char *tmp = imap_get_logical_part(part,type);
 		String_T str = p_string_new(self->pool, tmp);
+		size_t len = p_string_len(str);
 		g_free(tmp);
 
-		if (p_string_len(str) < 1) {
+		if (len < 1) {
 			dbmail_imap_session_buff_printf(self, "] NIL");
 		} else {
 			uint64_t cnt = 0;
 			if (bodyfetch->octetcnt > 0) {
-				cnt = get_dumpsize(bodyfetch, p_string_len(str));
+				cnt = get_dumpsize(bodyfetch, len);
 				dbmail_imap_session_buff_printf(self, "]<%" PRIu64 "> {%" PRIu64 "}\r\n", bodyfetch->octetstart, cnt);
-				p_string_erase(str,0,bodyfetch->octetstart);
+				p_string_erase(str,0,min(bodyfetch->octetstart,len));
 				p_string_truncate(str,cnt);
 			} else {
-				dbmail_imap_session_buff_printf(self, "] {%" PRIu64 "}\r\n", p_string_len(str));
+				dbmail_imap_session_buff_printf(self, "] {%" PRIu64 "}\r\n", len);
 			}
 			dbmail_imap_session_buff_printf(self,"%s", p_string_str(str));
 		}
-- 
2.10.1 (Apple Git-78)