Skip to content

Commit 63e50b8

Browse files
committed
Merge branch 'cb/bisect-helper-parser-fix'
The code to parse "git bisect start" command line was lax in validating the arguments. * cb/bisect-helper-parser-fix: bisect--helper: avoid segfault with bad syntax in `start --term-*`
2 parents 2bdf00e + 4d9005f commit 63e50b8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

builtin/bisect--helper.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,26 +455,31 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
455455
no_checkout = 1;
456456
} else if (!strcmp(arg, "--term-good") ||
457457
!strcmp(arg, "--term-old")) {
458+
i++;
459+
if (argc <= i)
460+
return error(_("'' is not a valid term"));
458461
must_write_terms = 1;
459462
free((void *) terms->term_good);
460-
terms->term_good = xstrdup(argv[++i]);
463+
terms->term_good = xstrdup(argv[i]);
461464
} else if (skip_prefix(arg, "--term-good=", &arg) ||
462465
skip_prefix(arg, "--term-old=", &arg)) {
463466
must_write_terms = 1;
464467
free((void *) terms->term_good);
465468
terms->term_good = xstrdup(arg);
466469
} else if (!strcmp(arg, "--term-bad") ||
467470
!strcmp(arg, "--term-new")) {
471+
i++;
472+
if (argc <= i)
473+
return error(_("'' is not a valid term"));
468474
must_write_terms = 1;
469475
free((void *) terms->term_bad);
470-
terms->term_bad = xstrdup(argv[++i]);
476+
terms->term_bad = xstrdup(argv[i]);
471477
} else if (skip_prefix(arg, "--term-bad=", &arg) ||
472478
skip_prefix(arg, "--term-new=", &arg)) {
473479
must_write_terms = 1;
474480
free((void *) terms->term_bad);
475481
terms->term_bad = xstrdup(arg);
476-
} else if (starts_with(arg, "--") &&
477-
!one_of(arg, "--term-good", "--term-bad", NULL)) {
482+
} else if (starts_with(arg, "--")) {
478483
return error(_("unrecognized option: '%s'"), arg);
479484
} else {
480485
char *commit_id = xstrfmt("%s^{commit}", arg);

t/t6030-bisect-porcelain.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,9 @@ test_expect_success 'bisect cannot mix terms' '
866866

867867
test_expect_success 'bisect terms rejects invalid terms' '
868868
git bisect reset &&
869+
test_must_fail git bisect start --term-good &&
869870
test_must_fail git bisect start --term-good invalid..term &&
871+
test_must_fail git bisect start --term-bad &&
870872
test_must_fail git bisect terms --term-bad invalid..term &&
871873
test_must_fail git bisect terms --term-good bad &&
872874
test_must_fail git bisect terms --term-good old &&

0 commit comments

Comments
 (0)