aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2013-01-11 03:31:45 +0800
committerMilan Crha <mcrha@redhat.com>2013-01-11 03:31:45 +0800
commit4d0463ddd38eebb56622b834197cbb891312f4ba (patch)
tree681c9b52a22b77eadc1fb519c1f2126c1776a4fc
parentf1e24f60ddd39e6ce2432c5bb5a37a5fae642b97 (diff)
downloadgsoc2013-evolution-4d0463ddd38eebb56622b834197cbb891312f4ba.tar.gz
gsoc2013-evolution-4d0463ddd38eebb56622b834197cbb891312f4ba.tar.zst
gsoc2013-evolution-4d0463ddd38eebb56622b834197cbb891312f4ba.zip
Be more strict in inline PGP mime filter/part parser
-rw-r--r--em-format/e-mail-inline-filter.c38
-rw-r--r--em-format/e-mail-parser-inlinepgp-encrypted.c4
-rw-r--r--em-format/e-mail-parser-inlinepgp-signed.c4
3 files changed, 40 insertions, 6 deletions
diff --git a/em-format/e-mail-inline-filter.c b/em-format/e-mail-inline-filter.c
index 1cd6781a06..8f31409d9e 100644
--- a/em-format/e-mail-inline-filter.c
+++ b/em-format/e-mail-inline-filter.c
@@ -199,6 +199,32 @@ inline_filter_add_part (EMailInlineFilter *emif,
emif->parts = g_slist_append (emif->parts, part);
}
+static gboolean
+newline_or_whitespace_follows (const gchar *str,
+ guint len,
+ guint skip_first)
+{
+ if (len <= skip_first)
+ return len == skip_first;
+
+ str += skip_first;
+ len -= skip_first;
+
+ while (len > 0 && *str != '\n') {
+ if (!*str)
+ return TRUE;
+
+
+ if (!camel_mime_is_lwsp (*str))
+ return FALSE;
+
+ len--;
+ str++;
+ }
+
+ return len == 0 || *str == '\n';
+}
+
static gint
inline_filter_scan (CamelMimeFilter *f,
gchar *in,
@@ -247,12 +273,14 @@ inline_filter_scan (CamelMimeFilter *f,
inline_filter_add_part (emif, data_start, start - data_start);
data_start = start;
emif->state = EMIF_POSTSCRIPT;
- } else if (rest_len >= 34 && strncmp (start, "-----BEGIN PGP SIGNED MESSAGE-----", 34) == 0) {
+ } else if (rest_len >= 34 && strncmp (start, "-----BEGIN PGP SIGNED MESSAGE-----", 34) == 0 &&
+ newline_or_whitespace_follows (start, rest_len, 34)) {
restore_inptr ();
inline_filter_add_part (emif, data_start, start - data_start);
data_start = start;
emif->state = EMIF_PGPSIGNED;
- } else if (rest_len >= 27 && strncmp (start, "-----BEGIN PGP MESSAGE-----", 27) == 0) {
+ } else if (rest_len >= 27 && strncmp (start, "-----BEGIN PGP MESSAGE-----", 27) == 0 &&
+ newline_or_whitespace_follows (start, rest_len, 27)) {
restore_inptr ();
inline_filter_add_part (emif, data_start, start - data_start);
data_start = start;
@@ -279,7 +307,8 @@ inline_filter_scan (CamelMimeFilter *f,
}
break;
case EMIF_PGPSIGNED:
- if (rest_len >= 27 && strncmp (start, "-----END PGP SIGNATURE-----", 27) == 0) {
+ if (rest_len >= 27 && strncmp (start, "-----END PGP SIGNATURE-----", 27) == 0 &&
+ newline_or_whitespace_follows (start, rest_len, 27)) {
restore_inptr ();
inline_filter_add_part (emif, data_start, inptr - data_start);
data_start = inptr;
@@ -288,7 +317,8 @@ inline_filter_scan (CamelMimeFilter *f,
}
break;
case EMIF_PGPENCRYPTED:
- if (rest_len >= 25 && strncmp (start, "-----END PGP MESSAGE-----", 25) == 0) {
+ if (rest_len >= 25 && strncmp (start, "-----END PGP MESSAGE-----", 25) == 0 &&
+ newline_or_whitespace_follows (start, rest_len, 25)) {
restore_inptr ();
inline_filter_add_part (emif, data_start, inptr - data_start);
data_start = inptr;
diff --git a/em-format/e-mail-parser-inlinepgp-encrypted.c b/em-format/e-mail-parser-inlinepgp-encrypted.c
index 3a61a5eeff..6b47ef0392 100644
--- a/em-format/e-mail-parser-inlinepgp-encrypted.c
+++ b/em-format/e-mail-parser-inlinepgp-encrypted.c
@@ -74,7 +74,9 @@ empe_inlinepgp_encrypted_parse (EMailParserExtension *extension,
GError *local_error = NULL;
GSList *parts, *iter;
- if (g_cancellable_is_cancelled (cancellable))
+ if (g_cancellable_is_cancelled (cancellable) ||
+ /* avoid recursion */
+ (part_id->str && part_id->len > 20 && g_str_has_suffix (part_id->str, ".inlinepgp_encrypted")))
return NULL;
cipher = camel_gpg_context_new (e_mail_parser_get_session (parser));
diff --git a/em-format/e-mail-parser-inlinepgp-signed.c b/em-format/e-mail-parser-inlinepgp-signed.c
index 23461299d9..84e85e10cc 100644
--- a/em-format/e-mail-parser-inlinepgp-signed.c
+++ b/em-format/e-mail-parser-inlinepgp-signed.c
@@ -79,7 +79,9 @@ empe_inlinepgp_signed_parse (EMailParserExtension *extension,
GByteArray *ba;
GSList *parts, *iter;
- if (g_cancellable_is_cancelled (cancellable))
+ if (g_cancellable_is_cancelled (cancellable) ||
+ /* avoid recursion */
+ (part_id->str && part_id->len > 17 && g_str_has_suffix (part_id->str, ".inlinepgp_signed")))
return NULL;
cipher = camel_gpg_context_new (e_mail_parser_get_session (parser));