]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mailinfo: disallow NUL character in mail's header
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>
Mon, 20 Apr 2020 23:54:36 +0000 (06:54 +0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Apr 2020 21:01:03 +0000 (14:01 -0700)
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mailinfo.c
t/t4254-am-corrupt.sh

index 0e9911df6d00bd6ba7320366cc42424b89b86651..5681d9130db6f54971cf2b966d1743b87a130b86 100644 (file)
@@ -1138,6 +1138,11 @@ static void handle_info(struct mailinfo *mi)
                else
                        continue;
 
+               if (memchr(hdr->buf, '\0', hdr->len)) {
+                       error("a NUL byte in '%s' is not allowed.", header[i]);
+                       mi->input_error = -1;
+               }
+
                if (!strcmp(header[i], "Subject")) {
                        if (!mi->keep_subject) {
                                cleanup_subject(mi, hdr);
index 1bbc37bc9231badc70527718a02d51cbfd3bebbb..daf01c309d03203026d27f2ff978974053e8eeee 100755 (executable)
@@ -70,10 +70,13 @@ test_expect_success "NUL in commit message's body" '
        grep "a NUL byte in commit log message not allowed" err
 '
 
-test_expect_failure "NUL in commit message's header" "
+test_expect_success "NUL in commit message's header" "
        test_when_finished 'git am --abort' &&
        make_mbox_with_nul subject >subject.patch &&
-       test_must_fail git am subject.patch
+       test_must_fail git mailinfo msg patch <subject.patch 2>err &&
+       grep \"a NUL byte in 'Subject' is not allowed\" err &&
+       test_must_fail git am subject.patch 2>err &&
+       grep \"a NUL byte in 'Subject' is not allowed\" err
 "
 
 test_done