From: Ken Hornstein Date: Tue, 4 Feb 2014 17:38:34 +0000 (-0500) Subject: More fixes (and tests) for the base64 encoder. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/628b193daced4357675de5127ff8129cf6f81b0f?ds=sidebyside;hp=be6c398415e30cc3cd1cc9098b2c4399e463b5a4 More fixes (and tests) for the base64 encoder. --- diff --git a/sbr/base64.c b/sbr/base64.c index 7ceb27b9..2fbef4b0 100644 --- a/sbr/base64.c +++ b/sbr/base64.c @@ -48,7 +48,15 @@ writeBase64aux (FILE *in, FILE *out, int crlf) * everything down and push the last character back. */ if (i == cc - 1) { - ungetc('\n', in); + /* + * If we're at the end of the input, there might be + * more room in inbuf; if so, add it there. Otherwise + * push it back to the input. + */ + if (cc < sizeof(inbuf)) + inbuf[cc++] = '\n'; + else + ungetc('\n', in); skipnl = 1; } else { /* This only works as long as sizeof(inbuf) == 3 */ diff --git a/test/mhbuild/test-cte b/test/mhbuild/test-cte index 128526a1..517fbc51 100755 --- a/test/mhbuild/test-cte +++ b/test/mhbuild/test-cte @@ -46,7 +46,8 @@ This is a test of a message with a sh=C3=B8rt line. EOF # -# Force some text to be base64 +# Force some text to be base64, to test out the encoder. Try at different +# line lengths to check out the padding on the # cat > "$draft" < "$draft" < +cc: +Fcc: +outbox +------ +# "$expected" < +cc: +Fcc: +outbox +MIME-Version: 1.0 +Content-Type: text/plain; charset="UTF-8" +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBhIHRlc3Qgb2YgYSBtw6tzc2FnZSB3aXRoIGEgc2jDuHJ0IGxpbmUuDQo= +EOF + +check "$draft" "$expected" + exit ${failed:-0}