diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libmime/mime_headers.c | 14 |
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, "?="); } |