From 1cbfce29fc0a81d40b14427c05bb458b600b2314 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sun, 28 Apr 2019 06:23:15 +0000 Subject: [PATCH] Correctly detect a "last boundary delimeter": --<boundary>-- Without this change, some attachment (e.g. from gmail) would not be correctly decoded because gmail would not insert any blank lines between the end of the nested multipart/alternative part and the beginning of the attachment part: --000000000000d75a0f058779bbb2-- --000000000000d75a12058779bbb4 Content-Type: image/jpeg; name="29571163_1640947089321419_3376478908098884084_n.jpg" Content-Disposition: attachment; filename="29571163_1640947089321419_3376478908098884084_n.jpg" Content-Transfer-Encoding: base64 It looks (from RFC2046) like boundary delimeters should actually be: "\r\n--<boundary>", but I'll look into that later. --- src/smblib/smbtxt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/smblib/smbtxt.c b/src/smblib/smbtxt.c index 904612b2ce..74f27fea05 100644 --- a/src/smblib/smbtxt.c +++ b/src/smblib/smbtxt.c @@ -361,6 +361,8 @@ static char* mime_getcontent(char* buf, const char* content_type, const char* co txt = buf; while((p = strstr(txt, boundary)) != NULL) { txt = p+strlen(boundary); + if(strncmp(txt, "--\r\n", 4) == 0) + break; SKIP_WHITESPACE(txt); p = strstr(txt, "\r\n\r\n"); /* End of header */ if(p==NULL) @@ -429,7 +431,7 @@ char* SMBCALL smb_getplaintext(smbmsg_t* msg, char* buf) return buf; } -/* Get just an attachment (just one) from MIME-encoded message body */ +/* Get just a base64-encoded attachment (just one) from MIME-encoded message body */ /* This function is destructive (over-writes 'buf' with decoded attachment)! */ uint8_t* SMBCALL smb_getattachment(smbmsg_t* msg, char* buf, char* filename, size_t filename_len, uint32_t* filelen, int index) { -- GitLab