Skip to content

Commit 1ea1e0e

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 9a7ea25 commit 1ea1e0e

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
@@ -1054,6 +1054,8 @@ static int process_replay_line(struct bisect_terms *terms, struct strbuf *line)
10541054
*word_end = '\0'; /* NUL-terminate the word */
10551055

10561056
get_terms(terms);
1057+
if (!terms->term_bad || !terms->term_good)
1058+
return error(_("no terms defined"));
10571059
if (check_and_set_terms(terms, p))
10581060
return -1;
10591061

@@ -1380,6 +1382,8 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
13801382
return error(_("'%s' requires 0 arguments"),
13811383
"git bisect next");
13821384
get_terms(&terms);
1385+
if (!terms.term_bad || !terms.term_good)
1386+
return error(_("no terms defined"));
13831387
res = bisect_next(&terms, prefix);
13841388
free_terms(&terms);
13851389
return res;
@@ -1414,6 +1418,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS
14141418

14151419
set_terms(&terms, "bad", "good");
14161420
get_terms(&terms);
1421+
if (!terms.term_bad || !terms.term_good)
1422+
return error(_("no terms defined"));
14171423
res = bisect_skip(&terms, argc, argv);
14181424
free_terms(&terms);
14191425
return res;
@@ -1426,6 +1432,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix
14261432
struct bisect_terms terms = { 0 };
14271433

14281434
get_terms(&terms);
1435+
if (!terms.term_bad || !terms.term_good)
1436+
return error(_("no terms defined"));
14291437
res = bisect_visualize(&terms, argc, argv);
14301438
free_terms(&terms);
14311439
return res;
@@ -1440,6 +1448,8 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
14401448
if (!argc)
14411449
return error(_("'%s' failed: no command provided."), "git bisect run");
14421450
get_terms(&terms);
1451+
if (!terms.term_bad || !terms.term_good)
1452+
return error(_("no terms defined"));
14431453
res = bisect_run(&terms, argc, argv);
14441454
free_terms(&terms);
14451455
return res;
@@ -1479,6 +1489,8 @@ int cmd_bisect(int argc,
14791489

14801490
set_terms(&terms, "bad", "good");
14811491
get_terms(&terms);
1492+
if (!terms.term_bad || !terms.term_good)
1493+
return error(_("no terms defined"));
14821494
if (check_and_set_terms(&terms, argv[0]) ||
14831495
!one_of(argv[0], terms.term_good, terms.term_bad, NULL))
14841496
usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,

0 commit comments

Comments
 (0)