Merge branch 'cc/git-shallow-file-wo-value'
The '--shallow-file' option of 'git' command requires a value, but the code did not check the presence of a value and instead segfaulted without one, which has been corrected. * cc/git-shallow-file-wo-value: git: avoid segfault on "git --shallow-file" without a valuemain
commit
32f49ed9f2
10
git.c
10
git.c
|
|
@ -304,11 +304,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
|
|||
if (envchanged)
|
||||
*envchanged = 1;
|
||||
} else if (!strcmp(cmd, "--shallow-file")) {
|
||||
(*argv)++;
|
||||
(*argc)--;
|
||||
setenv(GIT_SHALLOW_FILE_ENVIRONMENT, (*argv)[0], 1);
|
||||
if (*argc < 2) {
|
||||
fprintf(stderr, _("no file given for '%s' option\n" ), "--shallow-file");
|
||||
usage(git_usage_string);
|
||||
}
|
||||
setenv(GIT_SHALLOW_FILE_ENVIRONMENT, (*argv)[1], 1);
|
||||
if (envchanged)
|
||||
*envchanged = 1;
|
||||
(*argv)++;
|
||||
(*argc)--;
|
||||
} else if (!strcmp(cmd, "-C")) {
|
||||
if (*argc < 2) {
|
||||
fprintf(stderr, _("no directory given for '%s' option\n" ), "-C");
|
||||
|
|
|
|||
|
|
@ -107,4 +107,11 @@ test_expect_success 'for-each-ref usage error' '
|
|||
test_grep "usage" actual.err
|
||||
'
|
||||
|
||||
test_expect_success 'git --shallow-file without a value' '
|
||||
test_must_fail git --shallow-file >actual 2>actual.err &&
|
||||
test_line_count = 0 actual &&
|
||||
test_grep "no file given for " actual.err &&
|
||||
test_grep "usage" actual.err
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
|
|||
Loading…
Reference in New Issue