Code

notes: check number of parameters to "git notes copy"
authorJeff King <peff@peff.net>
Mon, 28 Jun 2010 08:59:07 +0000 (04:59 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Jun 2010 16:15:15 +0000 (09:15 -0700)
Otherwise we may segfault with too few parameters.

Signed-off-by: Jeff King <peff@peff.net>
Tested-by: Bert Wesarg <Bert.Wesarg@googlemail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/notes.c
t/t3301-notes.sh

index da504ee0af5dab303add0ddf210a7953ca87ae9d..f678f9cb520fa331de4899e372502cffccd9682c 100644 (file)
@@ -614,6 +614,10 @@ static int copy(int argc, const char **argv, const char *prefix)
                }
        }
 
+       if (argc < 2) {
+               error("too few parameters");
+               usage_with_options(git_notes_copy_usage, options);
+       }
        if (2 < argc) {
                error("too many parameters");
                usage_with_options(git_notes_copy_usage, options);
index 64f32ad94dfe842746774596b88c91e873da864f..2d67a40fc16385b8bee37968f4058b094a174a98 100755 (executable)
@@ -1044,4 +1044,10 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
        git log -1 > output &&
        test_cmp expect output
 '
+
+test_expect_success 'git notes copy diagnoses too many or too few parameters' '
+       test_must_fail git notes copy &&
+       test_must_fail git notes copy one two three
+'
+
 test_done