Skip to content

Commit db2cf6f

Browse files
committed
Merge branch 'jk/mailinfo-oob-read-fix'
OOB read fix. * jk/mailinfo-oob-read-fix: mailinfo: fix out-of-bounds memory reads in unquote_quoted_pair()
2 parents f09e741 + d1bd3a8 commit db2cf6f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

mailinfo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ 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;
6362

6463
strbuf_addch(outbuf, '(');
6564

66-
while ((c = *in++) != 0) {
65+
while (*in) {
66+
int c = *in++;
6767
if (take_next_literally == 1) {
6868
take_next_literally = 0;
6969
} else {
@@ -88,10 +88,10 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in)
8888

8989
static const char *unquote_quoted_string(struct strbuf *outbuf, const char *in)
9090
{
91-
int c;
9291
int take_next_literally = 0;
9392

94-
while ((c = *in++) != 0) {
93+
while (*in) {
94+
int c = *in++;
9595
if (take_next_literally == 1) {
9696
take_next_literally = 0;
9797
} 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

0 commit comments

Comments
 (0)