summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7d43de9)
raw | patch | inline | side by side (parent: 7d43de9)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Sun, 28 Nov 2010 19:42:46 +0000 (13:42 -0600) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 1 Dec 2010 21:26:52 +0000 (13:26 -0800) |
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>
--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>
fast-import.c | patch | blob | history | |
t/t9300-fast-import.sh | patch | blob | history |
diff --git a/fast-import.c b/fast-import.c
index 77549ebd6fbfbea051901d4ab474eebc8e2dbdbd..4bd9bf7d08905ab9e37671734e00222fb1b917ca 100644 (file)
--- a/fast-import.c
+++ b/fast-import.c
die("unknown --date-format argument %s", fmt);
}
+static unsigned long ulong_arg(const char *option, const char *arg)
+{
+ char *endptr;
+ unsigned long rv = strtoul(arg, &endptr, 0);
+ if (strchr(arg, '-') || endptr == arg || *endptr)
+ die("%s: argument must be a non-negative integer", option);
+ return rv;
+}
+
static void option_depth(const char *depth)
{
- max_depth = strtoul(depth, NULL, 0);
+ max_depth = ulong_arg("--depth", depth);
if (max_depth > MAX_DEPTH)
die("--depth cannot exceed %u", MAX_DEPTH);
}
static void option_active_branches(const char *branches)
{
- max_active_branches = strtoul(branches, NULL, 0);
+ max_active_branches = ulong_arg("--active-branches", branches);
}
static void option_export_marks(const char *marks)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 14d17691b1c48e2b3211812a16d6dda7e83ad31a..c80bb0cf10680dce5d28197416dff7d851aa553f 100755 (executable)
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
test_must_fail git fast-import --non-existing-option < /dev/null
'
+test_expect_success 'R: die on invalid option argument' '
+ echo "option git active-branches=-5" |
+ test_must_fail git fast-import &&
+ echo "option git depth=" |
+ test_must_fail git fast-import &&
+ test_must_fail git fast-import --depth="5 elephants" </dev/null
+'
+
cat >input <<EOF
option non-existing-vcs non-existing-option
EOF