]> granicus.if.org Git - git/commitdiff
rev-parse: demonstrate overflow of N for "foo^N" and "foo~N"
authorRené Scharfe <l.s.r@web.de>
Sun, 15 Sep 2019 12:03:25 +0000 (14:03 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Sep 2019 19:50:27 +0000 (12:50 -0700)
If the number gets too high for an int, weird things may happen, as
signed overflows are undefined.  Add a test to show this; rev-parse
"sucessfully" interprets 100000000000000000000000000000000 to be the
same as 0, at least on x64 with GCC 9.2.1 and Clang 8.0.1, which is
obviously bogus.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1506-rev-parse-diagnosis.sh

index 4ee009da666f22f6ff1ddce93dc1f30924c6cc26..5c4df474012ab76d6785fee42d2ec09cf8dee9b2 100755 (executable)
@@ -215,4 +215,12 @@ test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
        test_cmp expect actual
 '
 
+test_expect_failure 'reject Nth parent if N is too high' '
+       test_must_fail git rev-parse HEAD^100000000000000000000000000000000
+'
+
+test_expect_failure 'reject Nth ancestor if N is too high' '
+       test_must_fail git rev-parse HEAD~100000000000000000000000000000000
+'
+
 test_done