Skip to content

Commit 9fb44f4

Browse files
committed
bisect: check get_terms return at all call sites
Six callers of get_terms() silently discard its return value. When get_terms fails (missing or truncated BISECT_TERMS file), the term strings remain NULL or empty, causing confusing downstream behavior: commands like "bisect next" or "bisect run" proceed with empty term strings, producing nonsensical ref names (refs/bisect/ with no suffix) and misleading error messages. Add checks at each call site so that a failed get_terms produces a clear "no terms defined" error, matching the pattern already used in bisect_terms() at line 512. The check tests the term pointers rather than the return value because some callers (bisect skip, legacy bad/good) call set_terms before get_terms, and the set_terms values should survive a get_terms failure. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 3420d35 commit 9fb44f4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

builtin/bisect.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,8 @@ static int process_replay_line(struct bisect_terms *terms, struct strbuf *line)
10611061
*word_end = '\0'; /* NUL-terminate the word */
10621062

10631063
get_terms(terms);
1064+
if (!terms->term_bad || !terms->term_good)
1065+
return error(_("no terms defined"));
10641066
if (check_and_set_terms(terms, p))
10651067
return -1;
10661068

@@ -1387,6 +1389,8 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
13871389
return error(_("'%s' requires 0 arguments"),
13881390
"git bisect next");
13891391
get_terms(&terms);
1392+
if (!terms.term_bad || !terms.term_good)
1393+
return error(_("no terms defined"));
13901394
res = bisect_next(&terms, prefix);
13911395
free_terms(&terms);
13921396
return res;
@@ -1421,6 +1425,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS
14211425

14221426
set_terms(&terms, "bad", "good");
14231427
get_terms(&terms);
1428+
if (!terms.term_bad || !terms.term_good)
1429+
return error(_("no terms defined"));
14241430
res = bisect_skip(&terms, argc, argv);
14251431
free_terms(&terms);
14261432
return res;
@@ -1433,6 +1439,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix
14331439
struct bisect_terms terms = { 0 };
14341440

14351441
get_terms(&terms);
1442+
if (!terms.term_bad || !terms.term_good)
1443+
return error(_("no terms defined"));
14361444
res = bisect_visualize(&terms, argc, argv);
14371445
free_terms(&terms);
14381446
return res;
@@ -1447,6 +1455,8 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
14471455
if (!argc)
14481456
return error(_("'%s' failed: no command provided."), "git bisect run");
14491457
get_terms(&terms);
1458+
if (!terms.term_bad || !terms.term_good)
1459+
return error(_("no terms defined"));
14501460
res = bisect_run(&terms, argc, argv);
14511461
free_terms(&terms);
14521462
return res;
@@ -1486,6 +1496,8 @@ int cmd_bisect(int argc,
14861496

14871497
set_terms(&terms, "bad", "good");
14881498
get_terms(&terms);
1499+
if (!terms.term_bad || !terms.term_good)
1500+
return error(_("no terms defined"));
14891501
if (check_and_set_terms(&terms, argv[0]) ||
14901502
!one_of(argv[0], terms.term_good, terms.term_bad, NULL))
14911503
usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,

0 commit comments

Comments
 (0)