@matheusbsbs / matheus-bagliano / commits / 3919997447
Fork 0

mailinfo: disallow NUL character in mail's header

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Đoàn Trần Công Danh committed Apr 21, 2020 at 06:54 UTC 391999744771002cb5feded004879f36534b9b14
2 files changed +10 -2
mailinfo.c
+5
@@ -1138,6 +1138,11 @@ static void handle_info(struct mailinfo *mi)
1138 else
1139 continue;
1140
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 +
1146 if (!strcmp(header[i], "Subject")) {
1147 if (!mi->keep_subject) {
1148 cleanup_subject(mi, hdr);
t/t4254-am-corrupt.sh
+5 -2
@@ -70,10 +70,13 @@ test_expect_success "NUL in commit message's body" '
70 grep "a NUL byte in commit log message not allowed" err
71 '
72
73 -test_expect_failure "NUL in commit message's header" "
73 +test_expect_success "NUL in commit message's header" "
74 test_when_finished 'git am --abort' &&
75 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
80 "
81
82 test_done