aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-02-18 14:19:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-02-18 14:19:27 +0000
commit588ae7ce4366e1eff25bd388cf4cae99c57b63cc (patch)
treeb7fb0e1996cb4cfa00834f02819596e6372a67ea
parent81a0f3ca1152103eb0cd336bc4e2f5fabe6eef78 (diff)
downloadrspamd-588ae7ce4366e1eff25bd388cf4cae99c57b63cc.tar.gz
rspamd-588ae7ce4366e1eff25bd388cf4cae99c57b63cc.zip
[Fix] Fix rfc2231 for Content-Disposition header
Issue: #2757
-rw-r--r--src/libmime/content_type.c54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/libmime/content_type.c b/src/libmime/content_type.c
index ca371ce30..b67ec155e 100644
--- a/src/libmime/content_type.c
+++ b/src/libmime/content_type.c
@@ -305,8 +305,6 @@ rspamd_content_type_add_param (rspamd_mempool_t *pool,
nparam->value.len = value_end - value_start;
}
- RSPAMD_FTOK_ASSIGN (&srch, "charset");
-
srch.begin = nparam->name.begin;
srch.len = nparam->name.len;
@@ -713,36 +711,47 @@ rspamd_content_disposition_add_param (rspamd_mempool_t *pool,
const gchar *value_start, const gchar *value_end)
{
rspamd_ftok_t srch;
- gchar *decoded;
+ gchar *name_cpy, *value_cpy, *name_cpy_end, *value_cpy_end;
struct rspamd_content_type_param *found = NULL, *nparam;
g_assert (cd != NULL);
- srch.begin = name_start;
- srch.len = name_end - name_start;
+ name_cpy = rspamd_mempool_alloc (pool, name_end - name_start);
+ memcpy (name_cpy, name_start, name_end - name_start);
+ name_cpy_end = name_cpy + (name_end - name_start);
+
+ value_cpy = rspamd_mempool_alloc (pool, value_end - value_start);
+ memcpy (value_cpy, value_start, value_end - value_start);
+ value_cpy_end = value_cpy + (value_end - value_start);
+
+ nparam = rspamd_mempool_alloc0 (pool, sizeof (*nparam));
+ rspamd_str_lc (name_cpy, name_cpy_end - name_cpy);
+
+ if (!rspamd_param_maybe_rfc2231_process (pool, nparam, name_cpy,
+ name_cpy_end, value_cpy, value_cpy_end)) {
+ nparam->name.begin = name_cpy;
+ nparam->name.len = name_cpy_end - name_cpy;
+ nparam->value.begin = value_cpy;
+ nparam->value.len = value_cpy_end - value_cpy;
+ }
+
+ srch.begin = nparam->name.begin;
+ srch.len = nparam->name.len;
if (cd->attrs) {
found = g_hash_table_lookup (cd->attrs, &srch);
- }
- else {
+ } else {
cd->attrs = g_hash_table_new (rspamd_ftok_icase_hash,
rspamd_ftok_icase_equal);
- rspamd_mempool_add_destructor (pool,
- (rspamd_mempool_destruct_t)g_hash_table_unref, cd->attrs);
}
- nparam = rspamd_mempool_alloc0 (pool, sizeof (*nparam));
- nparam->name.begin = name_start;
- nparam->name.len = name_end - name_start;
- decoded = rspamd_mime_header_decode (pool, value_start,
- value_end - value_start, NULL);
- RSPAMD_FTOK_FROM_STR (&nparam->value, decoded);
-
if (!found) {
+ DL_APPEND (found, nparam);
g_hash_table_insert (cd->attrs, &nparam->name, nparam);
}
-
- DL_APPEND (found, nparam);
+ else {
+ DL_APPEND (found, nparam);
+ }
}
struct rspamd_content_disposition *
@@ -757,8 +766,13 @@ rspamd_content_disposition_parse (const gchar *in,
res->lc_data = rspamd_mempool_alloc (pool, len + 1);
rspamd_strlcpy (res->lc_data, in, len + 1);
rspamd_str_lc (res->lc_data, len);
- rspamd_postprocess_ct_attributes (pool, res->attrs,
- rspamd_content_disposition_postprocess, res);
+
+ if (res->attrs) {
+ rspamd_postprocess_ct_attributes (pool, res->attrs,
+ rspamd_content_disposition_postprocess, res);
+ rspamd_mempool_add_destructor (pool,
+ (rspamd_mempool_destruct_t)g_hash_table_unref, res->attrs);
+ }
}
else {
msg_warn_pool ("cannot parse content disposition: %*s",