t4211: log: demonstrate -L bounds checking bug
[gitweb.git] / t / t4211-line-log.sh
index 7665d6785c1a91ed0171e8cac61174ebee9b9a37..f98275c37cb261deea5aebaf44257e8da44fada2 100755 (executable)
@@ -64,6 +64,36 @@ test_bad_opts "-L 1,1000:b.c" "has only.*lines"
 test_bad_opts "-L :b.c" "argument.*not of the form"
 test_bad_opts "-L :foo:b.c" "no match"
 
+test_expect_success '-L X (X == nlines)' '
+       n=$(wc -l <b.c) &&
+       git log -L $n:b.c
+'
+
+test_expect_failure '-L X (X == nlines + 1)' '
+       n=$(expr $(wc -l <b.c) + 1) &&
+       test_must_fail git log -L $n:b.c
+'
+
+test_expect_success '-L X (X == nlines + 2)' '
+       n=$(expr $(wc -l <b.c) + 2) &&
+       test_must_fail git log -L $n:b.c
+'
+
+test_expect_success '-L ,Y (Y == nlines)' '
+       n=$(printf "%d" $(wc -l <b.c)) &&
+       git log -L ,$n:b.c
+'
+
+test_expect_success '-L ,Y (Y == nlines + 1)' '
+       n=$(expr $(wc -l <b.c) + 1) &&
+       test_must_fail git log -L ,$n:b.c
+'
+
+test_expect_success '-L ,Y (Y == nlines + 2)' '
+       n=$(expr $(wc -l <b.c) + 2) &&
+       test_must_fail git log -L ,$n:b.c
+'
+
 # There is a separate bug when an empty -L range is the first -L encountered,
 # thus to demonstrate this particular bug, the empty -L range must follow a
 # non-empty -L range.