commit 01073ff: [Fix] Mime_parser: Fix issue with parsing of the trailing garbadge
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Feb 19 10:00:05 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-02-19 09:58:51 +0000
URL: https://github.com/rspamd/rspamd/commit/01073ffc93bb5ac6578590900c50645a5c48126c (HEAD -> master)
[Fix] Mime_parser: Fix issue with parsing of the trailing garbadge
---
src/libmime/mime_parser.c | 34 +++++++++++++++++++++++++++++++---
src/libmime/mime_parser.h | 1 +
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c
index fb81c36ac..21a81575d 100644
--- a/src/libmime/mime_parser.c
+++ b/src/libmime/mime_parser.c
@@ -535,6 +535,7 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task,
struct rspamd_mime_parser_ctx *st,
struct rspamd_mime_part *multipart,
const gchar *start, const gchar *end,
+ gboolean is_finished,
GError **err)
{
struct rspamd_content_type *ct, *sel = NULL;
@@ -558,6 +559,24 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task,
*/
hdr_pos = 0;
body_pos = 0;
+
+ if (!is_finished) {
+ /* Ignore garbage */
+ const gchar *p = start;
+ gboolean seen_something = FALSE;
+
+ while (p < end) {
+ if (g_ascii_isalnum (*p)) {
+ seen_something = TRUE;
+ break;
+ }
+ p ++;
+ }
+
+ if (!seen_something) {
+ return RSPAMD_MIME_PARSE_NO_PART;
+ }
+ }
}
else {
hdr_pos = rspamd_string_find_eoh (&str, &body_pos);
@@ -681,8 +700,8 @@ rspamd_mime_parse_multipart_cb (struct rspamd_task *task,
g_assert (cb->cur_boundary != NULL);
if ((ret = rspamd_mime_process_multipart_node (task, cb->st,
- cb->multipart, cb->part_start, pos, cb->err))
- != RSPAMD_MIME_PARSE_OK) {
+ cb->multipart, cb->part_start, pos, TRUE, cb->err))
+ != RSPAMD_MIME_PARSE_OK) {
return ret;
}
@@ -1338,7 +1357,16 @@ rspamd_mime_parse_message (struct rspamd_task *task,
if (end > start &&
(ret = rspamd_mime_process_multipart_node (task, st,
- NULL, start, end, err)) != RSPAMD_MIME_PARSE_OK) {
+ NULL, start, end, FALSE, err)) != RSPAMD_MIME_PARSE_OK) {
+
+ if (nst != st) {
+ rspamd_mime_parse_stack_free (nst);
+ }
+
+ if (ret == RSPAMD_MIME_PARSE_NO_PART) {
+ return RSPAMD_MIME_PARSE_OK;
+ }
+
return ret;
}
}
diff --git a/src/libmime/mime_parser.h b/src/libmime/mime_parser.h
index 5164ea4d5..987ec1395 100644
--- a/src/libmime/mime_parser.h
+++ b/src/libmime/mime_parser.h
@@ -25,6 +25,7 @@ enum rspamd_mime_parse_error {
RSPAMD_MIME_PARSE_OK = 0,
RSPAMD_MIME_PARSE_FATAL,
RSPAMD_MIME_PARSE_NESTING,
+ RSPAMD_MIME_PARSE_NO_PART,
};
enum rspamd_mime_parse_error rspamd_mime_parse_task (struct rspamd_task *task,
More information about the Commits
mailing list