Skip to content

Commit 3919997

Browse files
sgngitster
authored andcommitted
mailinfo: disallow NUL character in mail's header
Signed-off-by: Đoàn Trần Công Danh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2a2ff60 commit 3919997

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mailinfo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,11 @@ static void handle_info(struct mailinfo *mi)
11381138
else
11391139
continue;
11401140

1141+
if (memchr(hdr->buf, '\0', hdr->len)) {
1142+
error("a NUL byte in '%s' is not allowed.", header[i]);
1143+
mi->input_error = -1;
1144+
}
1145+
11411146
if (!strcmp(header[i], "Subject")) {
11421147
if (!mi->keep_subject) {
11431148
cleanup_subject(mi, hdr);

t/t4254-am-corrupt.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ test_expect_success "NUL in commit message's body" '
7070
grep "a NUL byte in commit log message not allowed" err
7171
'
7272

73-
test_expect_failure "NUL in commit message's header" "
73+
test_expect_success "NUL in commit message's header" "
7474
test_when_finished 'git am --abort' &&
7575
make_mbox_with_nul subject >subject.patch &&
76-
test_must_fail git am subject.patch
76+
test_must_fail git mailinfo msg patch <subject.patch 2>err &&
77+
grep \"a NUL byte in 'Subject' is not allowed\" err &&
78+
test_must_fail git am subject.patch 2>err &&
79+
grep \"a NUL byte in 'Subject' is not allowed\" err
7780
"
7881

7982
test_done

0 commit comments

Comments
 (0)