Merge branch 'rj/add-i-leak-fix'
[git.git] / t / t4212-log-corrupt.sh
blobe6b59123a3725115ff2ad5eae495d114dc7df801
1 #!/bin/sh
3 test_description='git log with invalid commit headers'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
9 test_commit foo &&
11 git cat-file commit HEAD >ok.commit &&
12 sed "s/>/>-<>/" <ok.commit >broken_email.commit &&
14 git hash-object --literally -w -t commit broken_email.commit >broken_email.hash &&
15 git update-ref refs/heads/broken_email $(cat broken_email.hash)
18 test_expect_success 'fsck notices broken commit' '
19 test_must_fail git fsck 2>actual &&
20 test_grep invalid.author actual
23 test_expect_success 'git log with broken author email' '
25 echo commit $(cat broken_email.hash) &&
26 echo "Author: A U Thor <author@example.com>" &&
27 echo "Date: Thu Apr 7 15:13:13 2005 -0700" &&
28 echo &&
29 echo " foo"
30 } >expect.out &&
32 git log broken_email >actual.out 2>actual.err &&
34 test_cmp expect.out actual.out &&
35 test_must_be_empty actual.err
38 test_expect_success 'git log --format with broken author email' '
39 echo "A U Thor+author@example.com+Thu Apr 7 15:13:13 2005 -0700" >expect.out &&
41 git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&
43 test_cmp expect.out actual.out &&
44 test_must_be_empty actual.err
47 test_expect_success '--until handles broken email' '
48 git rev-list --until=1980-01-01 broken_email >actual &&
49 test_must_be_empty actual
52 munge_author_date () {
53 git cat-file commit "$1" >commit.orig &&
54 sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
55 git hash-object --literally -w -t commit commit.munge
58 test_expect_success 'unparsable dates produce sentinel value' '
59 commit=$(munge_author_date HEAD totally_bogus) &&
60 echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect &&
61 git log -1 $commit >actual.full &&
62 grep Date <actual.full >actual &&
63 test_cmp expect actual
66 test_expect_success 'unparsable dates produce sentinel value (%ad)' '
67 commit=$(munge_author_date HEAD totally_bogus) &&
68 echo >expect &&
69 git log -1 --format=%ad $commit >actual &&
70 test_cmp expect actual
73 # date is 2^64 + 1
74 test_expect_success 'date parser recognizes integer overflow' '
75 commit=$(munge_author_date HEAD 18446744073709551617) &&
76 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
77 git log -1 --format=%ad $commit >actual &&
78 test_cmp expect actual
81 # date is 2^64 - 2
82 test_expect_success 'date parser recognizes time_t overflow' '
83 commit=$(munge_author_date HEAD 18446744073709551614) &&
84 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
85 git log -1 --format=%ad $commit >actual &&
86 test_cmp expect actual
89 # date is within 2^63-1, but enough to choke glibc's gmtime
90 test_expect_success 'absurdly far-in-future date' '
91 commit=$(munge_author_date HEAD 999999999999999999) &&
92 git log -1 --format=%ad $commit
95 test_expect_success 'create commits with whitespace committer dates' '
96 # It is important that this subject line is numeric, since we want to
97 # be sure we are not confused by skipping whitespace and accidentally
98 # parsing the subject as a timestamp.
100 # Do not use munge_author_date here. Besides not hitting the committer
101 # line, it leaves the timezone intact, and we want nothing but
102 # whitespace.
104 # We will make two munged commits here. The first, ws_commit, will
105 # be purely spaces. The second contains a vertical tab, which is
106 # considered a space by strtoumax(), but not by our isspace().
107 test_commit 1234567890 &&
108 git cat-file commit HEAD >commit.orig &&
109 sed "s/>.*/> /" <commit.orig >commit.munge &&
110 ws_commit=$(git hash-object --literally -w -t commit commit.munge) &&
111 sed "s/>.*/> $(printf "\013")/" <commit.orig >commit.munge &&
112 vt_commit=$(git hash-object --literally -w -t commit commit.munge)
115 test_expect_success '--until treats whitespace date as sentinel' '
116 echo $ws_commit >expect &&
117 git rev-list --until=1980-01-01 $ws_commit >actual &&
118 test_cmp expect actual &&
120 echo $vt_commit >expect &&
121 git rev-list --until=1980-01-01 $vt_commit >actual &&
122 test_cmp expect actual
125 test_expect_success 'pretty-printer handles whitespace date' '
126 # as with the %ad test above, we will show these as the empty string,
127 # not the 1970 epoch date. This is intentional; see 7d9a281941 (t4212:
128 # test bogus timestamps with git-log, 2014-02-24) for more discussion.
129 echo : >expect &&
130 git log -1 --format="%at:%ct" $ws_commit >actual &&
131 test_cmp expect actual &&
132 git log -1 --format="%at:%ct" $vt_commit >actual &&
133 test_cmp expect actual
136 test_done