Hi all,
when encoding strings using qp_encode(), they might get wrapped among
multiple lines. qp_encode_calc_size() does not account for those
additional line breaks, though, which can at least crash mail(1).
How to reproduce:
$ echo -n 'öööööö...öööööö' | mail -s foo someuser
That's not the full command line, I actually used the ö 200 times (a
german umlaut, encoded as UTF-8, speaking in bytes this is 0xC3 0xB6).
The total length of this input is 400 bytes.
qp_encode_calc_size() returns 1203 which is not enough. It should return
at least 1233: Every input byte is encoded as three bytes (= 1200). This
will span ceil(1200 / 76) = 16 lines, so we get an additional 30 bytes
because every line break is "=\n". At the end of the encoded string,
there might be a "=\n" as well, so add another 2. Including the NUL
terminator, we end up at 1233.
Cheers!
Peter
>From 42140fd887fd698684d48d1ea6391774b0a26577 Mon Sep 17 00:00:00 2001
From: Peter Hofmann <[email protected]>
Date: Sun, 21 Sep 2014 09:11:34 +0200
Subject: [PATCH] Fix qp_encode_calc_size() when spanning multiple lines
---
mime_cte.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mime_cte.c b/mime_cte.c
index 9ed008a..44ec67f 100644
--- a/mime_cte.c
+++ b/mime_cte.c
@@ -332,7 +332,8 @@ qp_encode_calc_size(size_t len)
{
NYD_ENTER;
/* Worst case: 'CRLF' -> '=0D=0A=\n\0' */
- len = (len * 3) + 1/* soft NL */ + 1/* visual NL */ + 1/* NUL */;
+ len = (len * 3) + 1/* soft NL */ + 1/* visual NL */ + 1/* NUL */
+ + (2 * ((len * 3) / QP_LINESIZE))/* might span multiple lines */;
NYD_LEAVE;
return len;
}
--
2.1.0
------------------------------------------------------------------------------
Slashdot TV. Video for Nerds. Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
S-nail-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/s-nail-users