Merge branch 'jk/mailinfo-iterative-unquote-comment' into maint-2.43

The code to parse the From e-mail header has been updated to avoid
recursion.

* jk/mailinfo-iterative-unquote-comment:
  mailinfo: avoid recursion when unquoting From headers
  t5100: make rfc822 comment test more careful
  mailinfo: fix out-of-bounds memory reads in unquote_quoted_pair()
This commit is contained in:
Junio C Hamano
2024-02-08 16:22:03 -08:00
4 changed files with 34 additions and 8 deletions

View File

@ -58,12 +58,13 @@ static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line)
static const char *unquote_comment(struct strbuf *outbuf, const char *in)
{
int c;
int take_next_literally = 0;
int depth = 1;
strbuf_addch(outbuf, '(');
while ((c = *in++) != 0) {
while (*in) {
int c = *in++;
if (take_next_literally == 1) {
take_next_literally = 0;
} else {
@ -72,11 +73,14 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in)
take_next_literally = 1;
continue;
case '(':
in = unquote_comment(outbuf, in);
strbuf_addch(outbuf, '(');
depth++;
continue;
case ')':
strbuf_addch(outbuf, ')');
return in;
if (!--depth)
return in;
continue;
}
}
@ -88,10 +92,10 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in)
static const char *unquote_quoted_string(struct strbuf *outbuf, const char *in)
{
int c;
int take_next_literally = 0;
while ((c = *in++) != 0) {
while (*in) {
int c = *in++;
if (take_next_literally == 1) {
take_next_literally = 0;
} else {