Skip to content

Commit 119ab15

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: change die_on_unsafe_path() to check_unsafe_path()
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing. To do that in a compatible manner with the rest of the error handling in "builtin/apply.c", die_on_unsafe_path() should return a negative integer instead of calling die(), so while doing that let's change its name to check_unsafe_path(). Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dbf1b5f commit 119ab15

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

builtin/apply.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,7 +3704,7 @@ static int path_is_beyond_symlink(struct apply_state *state, const char *name_)
37043704
return ret;
37053705
}
37063706

3707-
static void die_on_unsafe_path(struct patch *patch)
3707+
static int check_unsafe_path(struct patch *patch)
37083708
{
37093709
const char *old_name = NULL;
37103710
const char *new_name = NULL;
@@ -3716,9 +3716,10 @@ static void die_on_unsafe_path(struct patch *patch)
37163716
new_name = patch->new_name;
37173717

37183718
if (old_name && !verify_path(old_name))
3719-
die(_("invalid path '%s'"), old_name);
3719+
return error(_("invalid path '%s'"), old_name);
37203720
if (new_name && !verify_path(new_name))
3721-
die(_("invalid path '%s'"), new_name);
3721+
return error(_("invalid path '%s'"), new_name);
3722+
return 0;
37223723
}
37233724

37243725
/*
@@ -3808,8 +3809,8 @@ static int check_patch(struct apply_state *state, struct patch *patch)
38083809
}
38093810
}
38103811

3811-
if (!state->unsafe_paths)
3812-
die_on_unsafe_path(patch);
3812+
if (!state->unsafe_paths && check_unsafe_path(patch))
3813+
return -128;
38133814

38143815
/*
38153816
* An attempt to read from or delete a path that is beyond a
@@ -3837,10 +3838,14 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
38373838
prepare_symlink_changes(state, patch);
38383839
prepare_fn_table(state, patch);
38393840
while (patch) {
3841+
int res;
38403842
if (state->apply_verbosely)
38413843
say_patch_name(stderr,
38423844
_("Checking patch %s..."), patch);
3843-
err |= check_patch(state, patch);
3845+
res = check_patch(state, patch);
3846+
if (res == -128)
3847+
return -128;
3848+
err |= res;
38443849
patch = patch->next;
38453850
}
38463851
return err;
@@ -4472,11 +4477,16 @@ static int apply_patch(struct apply_state *state,
44724477
goto end;
44734478
}
44744479

4475-
if ((state->check || state->apply) &&
4476-
check_patch_list(state, list) < 0 &&
4477-
!state->apply_with_reject) {
4478-
res = -1;
4479-
goto end;
4480+
if (state->check || state->apply) {
4481+
int r = check_patch_list(state, list);
4482+
if (r == -128) {
4483+
res = -128;
4484+
goto end;
4485+
}
4486+
if (r < 0 && !state->apply_with_reject) {
4487+
res = -1;
4488+
goto end;
4489+
}
44804490
}
44814491

44824492
if (state->apply && write_out_results(state, list)) {

0 commit comments

Comments
 (0)