aboutsummaryrefslogtreecommitdiffstats
path: root/apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-04-15 14:11:42 -0700
committerJunio C Hamano <gitster@pobox.com>2024-04-15 14:11:42 -0700
commitc7a9ec4728db6f88c0957789f3b77a3e2e8b0ec9 (patch)
tree1870ab934b6f8c65dbe26a58116f67e8c5da0594 /apply.c
parent509cc1d41394ea0d2308288a0cd3170c5774666e (diff)
parent708f7e05907ba7d4acd08bf87f51474471a16f43 (diff)
downloadgit-c7a9ec4728db6f88c0957789f3b77a3e2e8b0ec9.tar.gz
Merge branch 'rs/apply-lift-path-length-limit'
"git apply" has been updated to lift the hardcoded pathname length limit, which in turn allowed a mksnpath() function that is no longer used. * rs/apply-lift-path-length-limit: path: remove mksnpath() apply: avoid fixed-size buffer in create_one_file()
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/apply.c b/apply.c
index e311013bc4..a5f716a705 100644
--- a/apply.c
+++ b/apply.c
@@ -4448,6 +4448,7 @@ static int create_one_file(struct apply_state *state,
const char *buf,
unsigned long size)
{
+ char *newpath = NULL;
int res;
if (state->cached)
@@ -4509,24 +4510,26 @@ static int create_one_file(struct apply_state *state,
unsigned int nr = getpid();
for (;;) {
- char newpath[PATH_MAX];
- mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
+ newpath = mkpathdup("%s~%u", path, nr);
res = try_create_file(state, newpath, mode, buf, size);
if (res < 0)
- return -1;
+ goto out;
if (!res) {
if (!rename(newpath, path))
- return 0;
+ goto out;
unlink_or_warn(newpath);
break;
}
if (errno != EEXIST)
break;
++nr;
+ FREE_AND_NULL(newpath);
}
}
- return error_errno(_("unable to write file '%s' mode %o"),
- path, mode);
+ res = error_errno(_("unable to write file '%s' mode %o"), path, mode);
+out:
+ free(newpath);
+ return res;
}
static int add_conflicted_stages_file(struct apply_state *state,