git-mailinfo: Fix getting the subject from the in-body [PATCH] line
"Subject: " isn't in the static array "header", and thus memcmp("Subject:", header[i], 7) will never match. Even if it did so, hdr_data[] may not have been allocated if there weren't a "Subject: " in-body when we process "[PATCH]" in the affected codepath. Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lukas Sandström committed
Jul 10, 2008 at 23:41 UTC
e9fe804a8282107084a35d3a64e757daf217b042
7 files changed
+104
-2
builtin-mailinfo.c
+3
-1
@@ -334,7 +334,9 @@ static int check_header(char *line, unsigned linesize, char **hdr_data, int over
334
return 1;
335
if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) {
336
for (i = 0; header[i]; i++) {
337
- if (!memcmp("Subject: ", header[i], 9)) {
337
+ if (!memcmp("Subject", header[i], 7)) {
338
+ if (!hdr_data[i])
339
+ hdr_data[i] = xmalloc(linesize + 20);
340
if (! handle_header(line, hdr_data[i], 0)) {
341
return 1;
342
}
t/t5100-mailinfo.sh
+1
-1
@@ -11,7 +11,7 @@ test_expect_success 'split sample box' \
11
'git mailsplit -o. ../t5100/sample.mbox >last &&
12
last=`cat last` &&
13
echo total is $last &&
14
- test `cat last` = 9'
14
+ test `cat last` = 10'
15
16
for mail in `echo 00*`
17
do
t/t5100/0010
new
+35
@@ -0,0 +1,35 @@
1
+From b9704a518e21158433baa2cc2d591fea687967f6 Mon Sep 17 00:00:00 2001
2
+From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= <lukass@etek.chalmers.se>
3
+Date: Thu, 10 Jul 2008 23:41:33 +0200
4
+Subject: Re: discussion that lead to this patch
5
+MIME-Version: 1.0
6
+Content-Type: text/plain; charset=UTF-8
7
+Content-Transfer-Encoding: 8bit
8
+
9
+[PATCH] git-mailinfo: Fix getting the subject from the body
10
+
11
+"Subject: " isn't in the static array "header", and thus
12
+memcmp("Subject: ", header[i], 7) will never match.
13
+
14
+Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
15
+Signed-off-by: Junio C Hamano <gitster@pobox.com>
16
+---
17
+ builtin-mailinfo.c | 2 +-
18
+ 1 files changed, 1 insertions(+), 1 deletions(-)
19
+
20
+diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
21
+index 962aa34..2d1520f 100644
22
+--- a/builtin-mailinfo.c
23
++++ b/builtin-mailinfo.c
24
+@@ -334,7 +334,7 @@ static int check_header(char *line, unsigned linesize, char **hdr_data, int over
25
+ return 1;
26
+ if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) {
27
+ for (i = 0; header[i]; i++) {
28
+- if (!memcmp("Subject: ", header[i], 9)) {
29
++ if (!memcmp("Subject", header[i], 7)) {
30
+ if (! handle_header(line, hdr_data[i], 0)) {
31
+ return 1;
32
+ }
33
+--
34
+1.5.6.2.455.g1efb2
35
+
t/t5100/info0010
new
+5
@@ -0,0 +1,5 @@
1
+Author: Lukas Sandström
2
+Email: lukass@etek.chalmers.se
3
+Subject: git-mailinfo: Fix getting the subject from the body
4
+Date: Thu, 10 Jul 2008 23:41:33 +0200
5
+
t/t5100/msg0010
new
+5
@@ -0,0 +1,5 @@
1
+"Subject: " isn't in the static array "header", and thus
2
+memcmp("Subject: ", header[i], 7) will never match.
3
+
4
+Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
5
+Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5100/patch0010
new
+20
@@ -0,0 +1,20 @@
1
+---
2
+ builtin-mailinfo.c | 2 +-
3
+ 1 files changed, 1 insertions(+), 1 deletions(-)
4
+
5
+diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
6
+index 962aa34..2d1520f 100644
7
+--- a/builtin-mailinfo.c
8
++++ b/builtin-mailinfo.c
9
+@@ -334,7 +334,7 @@ static int check_header(char *line, unsigned linesize, char **hdr_data, int over
10
+ return 1;
11
+ if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) {
12
+ for (i = 0; header[i]; i++) {
13
+- if (!memcmp("Subject: ", header[i], 9)) {
14
++ if (!memcmp("Subject", header[i], 7)) {
15
+ if (! handle_header(line, hdr_data[i], 0)) {
16
+ return 1;
17
+ }
18
+--
19
+1.5.6.2.455.g1efb2
20
+
t/t5100/sample.mbox
+35
@@ -430,3 +430,38 @@ index b426a14..97756ec 100644
430
=20
431
=20
432
2. When the environment variable 'GIT_EXTERNAL_DIFF' is set, the
433
+From b9704a518e21158433baa2cc2d591fea687967f6 Mon Sep 17 00:00:00 2001
434
+From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= <lukass@etek.chalmers.se>
435
+Date: Thu, 10 Jul 2008 23:41:33 +0200
436
+Subject: Re: discussion that lead to this patch
437
+MIME-Version: 1.0
438
+Content-Type: text/plain; charset=UTF-8
439
+Content-Transfer-Encoding: 8bit
440
+
441
+[PATCH] git-mailinfo: Fix getting the subject from the body
442
+
443
+"Subject: " isn't in the static array "header", and thus
444
+memcmp("Subject: ", header[i], 7) will never match.
445
+
446
+Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
447
+Signed-off-by: Junio C Hamano <gitster@pobox.com>
448
+---
449
+ builtin-mailinfo.c | 2 +-
450
+ 1 files changed, 1 insertions(+), 1 deletions(-)
451
+
452
+diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
453
+index 962aa34..2d1520f 100644
454
+--- a/builtin-mailinfo.c
455
++++ b/builtin-mailinfo.c
456
+@@ -334,7 +334,7 @@ static int check_header(char *line, unsigned linesize, char **hdr_data, int over
457
+ return 1;
458
+ if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) {
459
+ for (i = 0; header[i]; i++) {
460
+- if (!memcmp("Subject: ", header[i], 9)) {
461
++ if (!memcmp("Subject", header[i], 7)) {
462
+ if (! handle_header(line, hdr_data[i], 0)) {
463
+ return 1;
464
+ }
465
+--
466
+1.5.6.2.455.g1efb2
467
+