commit 75ad544: [Fix] Uuencode: Fix parsing of corrupted uuencode
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Oct 25 17:00:07 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-10-25 17:56:32 +0100
URL: https://github.com/rspamd/rspamd/commit/75ad544ef49c646a02b9bddd434eb8d831ca487d (HEAD -> master)
[Fix] Uuencode: Fix parsing of corrupted uuencode
---
src/libmime/mime_parser.c | 6 +++---
src/libutil/str_util.c | 5 ++++-
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c
index e11b59e34..21374e249 100644
--- a/src/libmime/mime_parser.c
+++ b/src/libmime/mime_parser.c
@@ -568,11 +568,11 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
part->parsed_data.len = parsed->len;
}
else {
- msg_err_task ("invalid quoted-printable encoded part, assume 8bit");
+ msg_err_task ("invalid uuencoding in encoded part, assume 8bit");
part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
part->cte = RSPAMD_CTE_8BIT;
- memcpy (parsed->str, part->raw_data.begin, part->raw_data.len);
- parsed->len = part->raw_data.len;
+ parsed->len = MIN (part->raw_data.len, parsed->allocated);
+ memcpy (parsed->str, part->raw_data.begin, parsed->len);
part->parsed_data.begin = parsed->str;
part->parsed_data.len = parsed->len;
}
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 7edb1b109..d1f2cbfe6 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -2214,6 +2214,10 @@ rspamd_decode_uue_buf (const gchar *in, gsize inlen,
out_end = out + outlen;
remain = inlen;
+ /* Skip newlines */
+#define SKIP_NEWLINE do { while (remain > 0 && (*p == '\n' || *p == '\r')) {p ++; remain --; } } while (0)
+ SKIP_NEWLINE;
+
/* First of all, we need to read the first line (and probably skip it) */
if (remain < sizeof ("begin-base64 ")) {
/* Obviously truncated */
@@ -2247,7 +2251,6 @@ rspamd_decode_uue_buf (const gchar *in, gsize inlen,
return (-1);
}
-#define SKIP_NEWLINE do { while (remain > 0 && (*p == '\n' || *p == '\r')) {p ++; remain --; } } while (0)
#define DEC(c) (((c) - ' ') & 077) /* single character decode */
#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) )
#define CHAR_OUT(c) do { if (o < out_end) { *o++ = c; } else { return (-1); } } while(0)
More information about the Commits
mailing list