commit 9dcae9b: [Fix] Core: Fix headers folding on the last token

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Jan 31 12:42:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-01-31 12:19:43 +0000
URL: https://github.com/rspamd/rspamd/commit/9dcae9b27979fd4acc541d89877d74e6dc8e0980 (HEAD -> master)

[Fix] Core: Fix headers folding on the last token

---
 src/libutil/str_util.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index e72962904..2e09e48f3 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -1394,7 +1394,33 @@ rspamd_header_value_fold (const gchar *name,
 	case after_quote:
 		g_string_append_len (res, c, p - c);
 		break;
-
+	case fold_token:
+		/* Here, we have token start at 'c' and token end at 'p' */
+		if (g_ascii_isspace (res->str[res->len - 1])) {
+			g_string_append_len (res, c, p - c);
+		}
+		else {
+			if (*c != '\r' && *c != '\n') {
+				/* We need to add folding as well */
+				switch (how) {
+				case RSPAMD_TASK_NEWLINES_LF:
+					g_string_append_len (res, "\n\t", 2);
+					break;
+				case RSPAMD_TASK_NEWLINES_CR:
+					g_string_append_len (res, "\r\t", 2);
+					break;
+				case RSPAMD_TASK_NEWLINES_CRLF:
+				default:
+					g_string_append_len (res, "\r\n\t", 3);
+					break;
+				}
+				g_string_append_len (res, c, p - c);
+			}
+			else {
+				g_string_append_len (res, c, p - c);
+			}
+		}
+		break;
 	default:
 		g_assert (p == c);
 		break;


More information about the Commits mailing list