diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-09-23 11:58:24 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-09-23 11:58:24 +0100 |
commit | fa29b28616ece2ded9956c7da693412b61542daa (patch) | |
tree | ddc93911275ca933274a527e8b2ba883a289375c /src/libutil | |
parent | f5f509efb83b728dd54594d3259a10c5fcf695ee (diff) | |
download | rspamd-fa29b28616ece2ded9956c7da693412b61542daa.tar.gz rspamd-fa29b28616ece2ded9956c7da693412b61542daa.zip |
[Minor] More fixes to headers folding
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/str_util.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index ca40c86e4..3ebf297fc 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -1089,15 +1089,23 @@ rspamd_header_value_fold (const gchar *name, state = read_quoted; } else if (*p == '\r' || *p == '\n') { - /* Reset line length */ - cur_len = 0; - - while (g_ascii_isspace (*p)) { - p ++; + if (cur_len > fold_max && !first_token) { + fold_type = fold_before; + state = fold_token; + next_state = read_token; } + else { + /* Reset line length */ + cur_len = 0; - g_string_append_len (res, c, p - c); - c = p; + while (g_ascii_isspace (*p)) { + p ++; + } + + g_string_append_len (res, c, p - c); + c = p; + first_token = TRUE; + } } else if (g_ascii_isspace (*p)) { if (cur_len > fold_max * 0.8 && cur_len < fold_max) { @@ -1116,6 +1124,7 @@ rspamd_header_value_fold (const gchar *name, c = p; first_token = FALSE; p ++; + cur_len ++; } } else { @@ -1125,6 +1134,8 @@ rspamd_header_value_fold (const gchar *name, break; case fold_token: /* Here, we have token start at 'c' and token end at 'p' */ + g_assert (p > c); + if (fold_type == fold_after) { g_string_append_len (res, c, p - c); @@ -1145,10 +1156,12 @@ rspamd_header_value_fold (const gchar *name, if (g_ascii_isspace (*p)) { p ++; } + + cur_len = 0; } else { /* Skip space if needed */ - if (g_ascii_isspace (*c)) { + if (g_ascii_isspace (*c) && p > c) { c ++; } @@ -1166,12 +1179,12 @@ rspamd_header_value_fold (const gchar *name, } g_string_append_len (res, c, p - c); + cur_len = p - c; } + first_token = TRUE; c = p; state = next_state; - cur_len = 0; - first_token = TRUE; break; case read_quoted: |