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>

Eric Sunshine committed Jul 31, 2013 at 04:15 UTC 25fb8ee4450b3366bf1e9536a5585341d35b7b20
1 file changed +30
t/t4211-line-log.sh
+30
@@ -64,6 +64,36 @@ test_bad_opts "-L 1,1000:b.c" "has only.*lines"
64 test_bad_opts "-L :b.c" "argument.*not of the form"
65 test_bad_opts "-L :foo:b.c" "no match"
66
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 +
97 # There is a separate bug when an empty -L range is the first -L encountered,
98 # thus to demonstrate this particular bug, the empty -L range must follow a
99 # non-empty -L range.