Skip to content

Commit 45ef16f

Browse files
newrengitster
authored andcommitted
merge-recursive: add sanity checks for relevant merge_options
There are lots of options that callers can set, yet most have a limited range of valid values, some options are meant for output (e.g. opt->obuf, which is expected to start empty), and callers are expected to not set opt->priv. Add several sanity checks to ensure callers provide sane values. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3081da commit 45ef16f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

merge-recursive.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3615,6 +3615,30 @@ static int merge_start(struct merge_options *opt, struct tree *head)
36153615
{
36163616
struct strbuf sb = STRBUF_INIT;
36173617

3618+
/* Sanity checks on opt */
3619+
assert(opt->repo);
3620+
3621+
assert(opt->branch1 && opt->branch2);
3622+
3623+
assert(opt->detect_renames >= -1 &&
3624+
opt->detect_renames <= DIFF_DETECT_COPY);
3625+
assert(opt->detect_directory_renames >= MERGE_DIRECTORY_RENAMES_NONE &&
3626+
opt->detect_directory_renames <= MERGE_DIRECTORY_RENAMES_TRUE);
3627+
assert(opt->rename_limit >= -1);
3628+
assert(opt->rename_score >= 0 && opt->rename_score <= MAX_SCORE);
3629+
assert(opt->show_rename_progress >= 0 && opt->show_rename_progress <= 1);
3630+
3631+
assert(opt->xdl_opts >= 0);
3632+
assert(opt->recursive_variant >= MERGE_VARIANT_NORMAL &&
3633+
opt->recursive_variant <= MERGE_VARIANT_THEIRS);
3634+
3635+
assert(opt->verbosity >= 0 && opt->verbosity <= 5);
3636+
assert(opt->buffer_output <= 2);
3637+
assert(opt->obuf.len == 0);
3638+
3639+
assert(opt->priv == NULL);
3640+
3641+
/* Sanity check on repo state; index must match head */
36183642
if (repo_index_has_changes(opt->repo, head, &sb)) {
36193643
err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"),
36203644
sb.buf);

0 commit comments

Comments
 (0)