aboutsummaryrefslogtreecommitdiffstats
path: root/apply.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2023-02-06 09:24:06 +0100
committerJohannes Schindelin <johannes.schindelin@gmx.de>2023-02-06 09:24:06 +0100
commite14d6b8408a2a283e55ca64d2c77ac929ec77204 (patch)
tree87fdd060e84cdaaf757d51427010d431b56ab1fd /apply.c
parentf8bf6b8f3db21d08d0ef0133b185d2b26f21d041 (diff)
parent394a759d2b5f0a1a1908c820cf142f45cb78718c (diff)
downloadgit-e14d6b8408a2a283e55ca64d2c77ac929ec77204.tar.gz
Sync with 2.30.8
* maint-2.30: Git 2.30.8 apply: fix writing behind newly created symbolic links dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS clone: delay picking a transport until after get_repo_path() t5619: demonstrate clone_local() with ambiguous transport
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/apply.c b/apply.c
index 6695a931e9..084c6dde7a 100644
--- a/apply.c
+++ b/apply.c
@@ -4400,6 +4400,33 @@ static int create_one_file(struct apply_state *state,
if (state->cached)
return 0;
+ /*
+ * We already try to detect whether files are beyond a symlink in our
+ * up-front checks. But in the case where symlinks are created by any
+ * of the intermediate hunks it can happen that our up-front checks
+ * didn't yet see the symlink, but at the point of arriving here there
+ * in fact is one. We thus repeat the check for symlinks here.
+ *
+ * Note that this does not make the up-front check obsolete as the
+ * failure mode is different:
+ *
+ * - The up-front checks cause us to abort before we have written
+ * anything into the working directory. So when we exit this way the
+ * working directory remains clean.
+ *
+ * - The checks here happen in the middle of the action where we have
+ * already started to apply the patch. The end result will be a dirty
+ * working directory.
+ *
+ * Ideally, we should update the up-front checks to catch what would
+ * happen when we apply the patch before we damage the working tree.
+ * We have all the information necessary to do so. But for now, as a
+ * part of embargoed security work, having this check would serve as a
+ * reasonable first step.
+ */
+ if (path_is_beyond_symlink(state, path))
+ return error(_("affected file '%s' is beyond a symbolic link"), path);
+
res = try_create_file(state, path, mode, buf, size);
if (res < 0)
return -1;