log: fix -L bounds checking bug
authorEric Sunshine <sunshine@sunshineco.com>
Wed, 31 Jul 2013 08:15:41 +0000 (04:15 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Aug 2013 18:54:32 +0000 (11:54 -0700)
When 12da1d1f added -L support to git-log, a broken bounds check was
copied from git-blame -L which incorrectly allows -LX to extend one line
past end of file without reporting an error. Instead, it generates an
empty range. Fix this bug.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
line-log.c
t/t4211-line-log.sh
index c2d01dccc2a12a767c442de58ed78df130699d74..1c3ac8dccd1dd7c1c15aaa82e80d6dbdf129bb56 100644 (file)
@@ -594,13 +594,13 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
                                    lines, &begin, &end,
                                    full_name))
                        die("malformed -L argument '%s'", range_part);
+               if (lines < end || ((lines || begin) && lines < begin))
+                       die("file %s has only %lu lines", name_part, lines);
                if (begin < 1)
                        begin = 1;
                if (end < 1)
                        end = lines;
                begin--;
-               if (lines < end || lines < begin)
-                       die("file %s has only %ld lines", name_part, lines);
                line_log_data_insert(&ranges, full_name, begin, end);
 
                free_filespec(spec);
index 769ac686c388d9378a273c05e34642410c3566a3..b01b3ddebb568e0fe74843d29933b5f0cda1a7d3 100755 (executable)
@@ -69,7 +69,7 @@ test_expect_success '-L X (X == nlines)' '
        git log -L $n:b.c
 '
 
-test_expect_failure '-L X (X == nlines + 1)' '
+test_expect_success '-L X (X == nlines + 1)' '
        n=$(expr $(wc -l <b.c) + 1) &&
        test_must_fail git log -L $n:b.c
 '