From: Junio C Hamano Date: Wed, 18 Oct 2017 05:19:03 +0000 (+0900) Subject: Merge branch 'rs/mailinfo-qp-decode-fix' into maint X-Git-Tag: v2.15.0-rc2~5^2~35 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/01ae81e028f35fedac97e6e44336305786c3f14c?hp=b8a4e894d42dd3b1c5dfa90e68ffaee5ab27dcc2 Merge branch 'rs/mailinfo-qp-decode-fix' into maint "git mailinfo" was loose in decoding quoted printable and produced garbage when the two letters after the equal sign are not hexadecimal. This has been fixed. * rs/mailinfo-qp-decode-fix: mailinfo: don't decode invalid =XY quoted-printable sequences --- diff --git a/mailinfo.c b/mailinfo.c index bd574cb752..70187e3eb3 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -368,11 +368,16 @@ static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047) while ((c = *in++) != 0) { if (c == '=') { - int d = *in++; + int ch, d = *in; if (d == '\n' || !d) break; /* drop trailing newline */ - strbuf_addch(out, (hexval(d) << 4) | hexval(*in++)); - continue; + ch = hex2chr(in); + if (ch >= 0) { + strbuf_addch(out, ch); + in += 2; + continue; + } + /* garbage -- fall through */ } if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */ c = 0x20;