Skip to content

Commit 25fb8ee

Browse files
sunshinecogitster
authored andcommitted
t4211: log: demonstrate -L bounds checking bug
A bounds checking bug allows the X in -LX to extend one line past the end of file. For example, given a file with 5 lines, -L6 is accepted as valid. Demonstrate this problem. While here, also add tests to check that the remaining cases of X and Y in -LX,Y are handled correctly at and in the vicinity of end-of-file. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 164a9cf commit 25fb8ee

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

t/t4211-line-log.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,36 @@ test_bad_opts "-L 1,1000:b.c" "has only.*lines"
6464
test_bad_opts "-L :b.c" "argument.*not of the form"
6565
test_bad_opts "-L :foo:b.c" "no match"
6666

67+
test_expect_success '-L X (X == nlines)' '
68+
n=$(wc -l <b.c) &&
69+
git log -L $n:b.c
70+
'
71+
72+
test_expect_failure '-L X (X == nlines + 1)' '
73+
n=$(expr $(wc -l <b.c) + 1) &&
74+
test_must_fail git log -L $n:b.c
75+
'
76+
77+
test_expect_success '-L X (X == nlines + 2)' '
78+
n=$(expr $(wc -l <b.c) + 2) &&
79+
test_must_fail git log -L $n:b.c
80+
'
81+
82+
test_expect_success '-L ,Y (Y == nlines)' '
83+
n=$(printf "%d" $(wc -l <b.c)) &&
84+
git log -L ,$n:b.c
85+
'
86+
87+
test_expect_success '-L ,Y (Y == nlines + 1)' '
88+
n=$(expr $(wc -l <b.c) + 1) &&
89+
test_must_fail git log -L ,$n:b.c
90+
'
91+
92+
test_expect_success '-L ,Y (Y == nlines + 2)' '
93+
n=$(expr $(wc -l <b.c) + 2) &&
94+
test_must_fail git log -L ,$n:b.c
95+
'
96+
6797
# There is a separate bug when an empty -L range is the first -L encountered,
6898
# thus to demonstrate this particular bug, the empty -L range must follow a
6999
# non-empty -L range.

0 commit comments

Comments
 (0)