@matheusbsbs / matheus-bagliano / commits / a9ff277e58
Fork 0

fast-import: stricter parsing of integer options

Check the result from strtoul to avoid accepting arguments like --depth=-1 and --active-branches=foo,bar,baz. Requested-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 28, 2010 at 13:42 UTC a9ff277e583782346181f431784e48046b0dfaa9
2 files changed +19 -2
fast-import.c
+11 -2
@@ -2746,16 +2746,25 @@ static void option_date_format(const char *fmt)
2746 die("unknown --date-format argument %s", fmt);
2747 }
2748
2749 +static unsigned long ulong_arg(const char *option, const char *arg)
2750 +{
2751 + char *endptr;
2752 + unsigned long rv = strtoul(arg, &endptr, 0);
2753 + if (strchr(arg, '-') || endptr == arg || *endptr)
2754 + die("%s: argument must be a non-negative integer", option);
2755 + return rv;
2756 +}
2757 +
2758 static void option_depth(const char *depth)
2759 {
2751 - max_depth = strtoul(depth, NULL, 0);
2760 + max_depth = ulong_arg("--depth", depth);
2761 if (max_depth > MAX_DEPTH)
2762 die("--depth cannot exceed %u", MAX_DEPTH);
2763 }
2764
2765 static void option_active_branches(const char *branches)
2766 {
2758 - max_active_branches = strtoul(branches, NULL, 0);
2767 + max_active_branches = ulong_arg("--active-branches", branches);
2768 }
2769
2770 static void option_export_marks(const char *marks)
t/t9300-fast-import.sh
+8
@@ -1659,6 +1659,14 @@ test_expect_success 'R: unknown commandline options are rejected' '\
1659 test_must_fail git fast-import --non-existing-option < /dev/null
1660 '
1661
1662 +test_expect_success 'R: die on invalid option argument' '
1663 + echo "option git active-branches=-5" |
1664 + test_must_fail git fast-import &&
1665 + echo "option git depth=" |
1666 + test_must_fail git fast-import &&
1667 + test_must_fail git fast-import --depth="5 elephants" </dev/null
1668 +'
1669 +
1670 cat >input <<EOF
1671 option non-existing-vcs non-existing-option
1672 EOF