aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-11-16 17:46:44 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-11-16 17:46:44 +0000
commit0806e4d11bcc08bdc3b8efbf55c372f844b0a722 (patch)
treebde5845a7a012f2dbf98e8d268ee1adb5b4a3658 /src
parent7be5889e7033f019adb7310685121babf6f802d4 (diff)
downloadrspamd-0806e4d11bcc08bdc3b8efbf55c372f844b0a722.tar.gz
rspamd-0806e4d11bcc08bdc3b8efbf55c372f844b0a722.zip
[Fix] Some more fixes
Diffstat (limited to 'src')
-rw-r--r--src/libmime/mime_headers.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c
index 9d11210f3..3565eefba 100644
--- a/src/libmime/mime_headers.c
+++ b/src/libmime/mime_headers.c
@@ -818,10 +818,9 @@ rspamd_mime_header_decode(rspamd_mempool_t *pool, const char *in,
char *
rspamd_mime_header_encode(const char *in, gsize len)
{
- static const size_t max_token_size = 76;
+ static const size_t max_token_size = 76 - (sizeof("=?UTF-8?Q? ?=") - 3);
GString *outbuf = g_string_sized_new(len);
- size_t encode_buf_size = max_token_size;
- char *encode_buf = g_alloca(encode_buf_size + 3);
+ char *encode_buf = g_alloca(max_token_size + 3);
const char *p = in;
const char *end = in + len;
@@ -853,13 +852,20 @@ rspamd_mime_header_encode(const char *in, gsize len)
}
else {
encoded_len++;
+
+ if (encoded_len > max_token_size) {
+ piece_len = i - 1;
+ q = p + piece_len;
+ /* No more space */
+ break;
+ }
}
}
if (has_non_ascii) {
g_string_append(outbuf, "=?UTF-8?Q?");
/* Do encode */
- gssize encoded_len = rspamd_encode_qp2047_buf(p, piece_len, encode_buf, encode_buf_size);
+ encoded_len = rspamd_encode_qp2047_buf(p, piece_len, encode_buf, max_token_size);
g_string_append_len(outbuf, encode_buf, encoded_len);
g_string_append(outbuf, "?=");
}