Skip to content

Commit 0e92593

Browse files
committed
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()
2 parents 952916f + dee1829 commit 0e92593

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

mailinfo.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line)
5858

5959
static const char *unquote_comment(struct strbuf *outbuf, const char *in)
6060
{
61-
int c;
6261
int take_next_literally = 0;
62+
int depth = 1;
6363

6464
strbuf_addch(outbuf, '(');
6565

66-
while ((c = *in++) != 0) {
66+
while (*in) {
67+
int c = *in++;
6768
if (take_next_literally == 1) {
6869
take_next_literally = 0;
6970
} else {
@@ -72,11 +73,14 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in)
7273
take_next_literally = 1;
7374
continue;
7475
case '(':
75-
in = unquote_comment(outbuf, in);
76+
strbuf_addch(outbuf, '(');
77+
depth++;
7678
continue;
7779
case ')':
7880
strbuf_addch(outbuf, ')');
79-
return in;
81+
if (!--depth)
82+
return in;
83+
continue;
8084
}
8185
}
8286

@@ -88,10 +92,10 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in)
8892

8993
static const char *unquote_quoted_string(struct strbuf *outbuf, const char *in)
9094
{
91-
int c;
9295
int take_next_literally = 0;
9396

94-
while ((c = *in++) != 0) {
97+
while (*in) {
98+
int c = *in++;
9599
if (take_next_literally == 1) {
96100
take_next_literally = 0;
97101
} else {

t/t5100-mailinfo.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,26 @@ test_expect_success 'mailinfo warn CR in base64 encoded email' '
268268
test_must_be_empty quoted-cr/0002.err
269269
'
270270

271+
test_expect_success 'from line with unterminated quoted string' '
272+
echo "From: bob \"unterminated string smith <[email protected]>" >in &&
273+
git mailinfo /dev/null /dev/null <in >actual &&
274+
cat >expect <<-\EOF &&
275+
Author: bob unterminated string smith
276+
277+
278+
EOF
279+
test_cmp expect actual
280+
'
281+
282+
test_expect_success 'from line with unterminated comment' '
283+
echo "From: bob (unterminated comment smith <[email protected]>" >in &&
284+
git mailinfo /dev/null /dev/null <in >actual &&
285+
cat >expect <<-\EOF &&
286+
Author: bob (unterminated comment smith
287+
288+
289+
EOF
290+
test_cmp expect actual
291+
'
292+
271293
test_done

t/t5100/comment.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Author: A U Thor (this is (really) a comment (honestly))
1+
Author: (this is (really) a "comment" (honestly)) A U Thor
22
33
Subject: testing comments
44
Date: Sun, 25 May 2008 00:38:18 -0700

t/t5100/comment.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
2-
From: "A U Thor" <[email protected]> (this is \(really\) a comment (honestly))
2+
From: (this is \(really\) a "comment" (honestly)) "A U Thor" <[email protected]>
33
Date: Sun, 25 May 2008 00:38:18 -0700
44
Subject: [PATCH] testing comments
55

0 commit comments

Comments
 (0)