aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-02-08 16:22:03 -0800
committerJunio C Hamano <gitster@pobox.com>2024-02-08 16:22:03 -0800
commit0e92593acfd76fc5efc8f020d14c4540a89289d5 (patch)
treef05768e086a8e2bec70ded13a4042579f37daa8a
parent952916f9e0d234ef4d0e1de0a4d8eae27ebfb16c (diff)
parentdee182941fb685f5d85e61a0e9d97e8e91512f6c (diff)
downloadgit-0e92593acfd76fc5efc8f020d14c4540a89289d5.tar.gz
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()
-rw-r--r--mailinfo.c16
-rwxr-xr-xt/t5100-mailinfo.sh22
-rw-r--r--t/t5100/comment.expect2
-rw-r--r--t/t5100/comment.in2
4 files changed, 34 insertions, 8 deletions
diff --git a/mailinfo.c b/mailinfo.c
index 093bed5d8f..94b9b0abf2 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -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 {
diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh
index db11cababd..654d8cf3ee 100755
--- a/t/t5100-mailinfo.sh
+++ b/t/t5100-mailinfo.sh
@@ -268,4 +268,26 @@ test_expect_success 'mailinfo warn CR in base64 encoded email' '
test_must_be_empty quoted-cr/0002.err
'
+test_expect_success 'from line with unterminated quoted string' '
+ echo "From: bob \"unterminated string smith <bob@example.com>" >in &&
+ git mailinfo /dev/null /dev/null <in >actual &&
+ cat >expect <<-\EOF &&
+ Author: bob unterminated string smith
+ Email: bob@example.com
+
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'from line with unterminated comment' '
+ echo "From: bob (unterminated comment smith <bob@example.com>" >in &&
+ git mailinfo /dev/null /dev/null <in >actual &&
+ cat >expect <<-\EOF &&
+ Author: bob (unterminated comment smith
+ Email: bob@example.com
+
+ EOF
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t5100/comment.expect b/t/t5100/comment.expect
index 7228177984..bd71956a47 100644
--- a/t/t5100/comment.expect
+++ b/t/t5100/comment.expect
@@ -1,4 +1,4 @@
-Author: A U Thor (this is (really) a comment (honestly))
+Author: (this is (really) a "comment" (honestly)) A U Thor
Email: somebody@example.com
Subject: testing comments
Date: Sun, 25 May 2008 00:38:18 -0700
diff --git a/t/t5100/comment.in b/t/t5100/comment.in
index c53a192dfe..0b7e903b06 100644
--- a/t/t5100/comment.in
+++ b/t/t5100/comment.in
@@ -1,5 +1,5 @@
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
-From: "A U Thor" <somebody@example.com> (this is \(really\) a comment (honestly))
+From: (this is \(really\) a "comment" (honestly)) "A U Thor" <somebody@example.com>
Date: Sun, 25 May 2008 00:38:18 -0700
Subject: [PATCH] testing comments