git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] "git apply" safety
@ 2015-02-02 23:27 Junio C Hamano
  2015-02-02 23:27 ` [PATCH v2 1/4] apply: reject input that touches outside $cwd Junio C Hamano
                   ` (4 more replies)
  0 siblings, 5 replies; 34+ messages in thread
From: Junio C Hamano @ 2015-02-02 23:27 UTC (permalink / raw)
  To: git

"git apply" have been fairly careless about letting the input follow
symbolic links, especially when used without the --index/--cached
options (which was more or less deliberate to mimic what "patch"
used to do).  When the input tells it to modify a/b/c, and lstat(2)
said that there is "a/b/c" that matches the preimage in the input,
we happily overwrote it, even when a/b is a symbolic link that
pointed somewhere, even outside the working tree.

This series tightens things a bit for safety.

 (1) By default, we reject patches to ".git/file", "../some/where",
     "./this/././that", etc., i.e. the names you cannot add to the
     index.  Those who use "git apply" (without --index/--cached) as
     a replacement for GNU patch can use --unsafe-paths option to
     override this safety.  This is what patch 1/4 does.

 (2) We do not allow a patch to depend on a location beyond a
     symbolic link (this includes "a patch to remove a path beyond a
     symbolic link").  This is patch 2/4 and 3/4.

 (3) We do not allow a patch to create result on a location beyond a
     symbolic link.  This is patch 4/4.

There is no knob to override the latter two points, as this is not a
safety but is a correctness issue.  Because Git keeps track of and
can express changes to symbolic links, a patch that expects a file
"a/b/c" to be tracked (either the patch adds it, or it modifies an
existing file tehre) implicitly expects that there is no symbolic
link "a/b", so attempting to apply such a patch to a tree with a
symbolic link at "a/b", even when the link points at some directory,
must detect that the target tree does not match what the patch's
preimage expects and fail.

The previous attempt begins at around here:

  http://thread.gmane.org/gmane.linux.kernel/1874498/focus=1878385

Junio C Hamano (4):
  apply: reject input that touches outside $cwd
  apply: do not read from the filesystem under --index
  apply: do not read from beyond a symbolic link
  apply: do not touch a file beyond a symbolic link

 Documentation/git-apply.txt     |  14 +++-
 builtin/apply.c                 | 139 +++++++++++++++++++++++++++++++++++++++-
 t/t4122-apply-symlink-inside.sh |  89 +++++++++++++++++++++++++
 t/t4139-apply-escape.sh         | 137 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 377 insertions(+), 2 deletions(-)
 create mode 100755 t/t4139-apply-escape.sh

-- 
2.3.0-rc2-164-g799cdce

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2015-02-10 22:36 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-02 23:27 [PATCH v2 0/4] "git apply" safety Junio C Hamano
2015-02-02 23:27 ` [PATCH v2 1/4] apply: reject input that touches outside $cwd Junio C Hamano
2015-02-03  0:45   ` Jeff King
2015-02-03  0:50   ` Jeff King
2015-02-03 20:23     ` Junio C Hamano
2015-02-03 21:01       ` Jeff King
2015-02-03 21:23         ` Junio C Hamano
2015-02-03 21:24           ` Jeff King
2015-02-03 21:40             ` Junio C Hamano
2015-02-03 21:50               ` Jeff King
2015-02-03 22:11                 ` Junio C Hamano
2015-02-03  5:56   ` Torsten Bögershausen
2015-02-02 23:27 ` [PATCH v2 2/4] apply: do not read from the filesystem under --index Junio C Hamano
2015-02-02 23:27 ` [PATCH v2 3/4] apply: do not read from beyond a symbolic link Junio C Hamano
2015-02-03  0:08   ` Stefan Beller
2015-02-03 19:37     ` Junio C Hamano
2015-02-03 19:44       ` Stefan Beller
2015-02-03 20:31         ` Junio C Hamano
2015-02-02 23:27 ` [PATCH v2 4/4] apply: do not touch a file " Junio C Hamano
2015-02-03  1:11   ` Jeff King
2015-02-03  1:56     ` Junio C Hamano
2015-02-03  2:04       ` Jeff King
2015-02-03 21:01     ` Junio C Hamano
2015-02-03 23:40       ` Eric Sunshine
2015-02-04  0:44 ` [PATCH v3 0/4] "git apply" safety Junio C Hamano
2015-02-04  0:44   ` [PATCH v3 1/4] apply: reject input that touches outside the working area Junio C Hamano
2015-02-04  0:44   ` [PATCH v3 2/4] apply: do not read from the filesystem under --index Junio C Hamano
2015-02-04  0:44   ` [PATCH v3 3/4] apply: do not read from beyond a symbolic link Junio C Hamano
2015-02-04  0:44   ` [PATCH v3 4/4] apply: do not touch a file " Junio C Hamano
2015-02-10 22:36   ` [PATCH v4 0/4] "git apply" safety Junio C Hamano
2015-02-10 22:36     ` [PATCH v4 1/4] apply: reject input that touches outside the working area Junio C Hamano
2015-02-10 22:36     ` [PATCH v4 2/4] apply: do not read from the filesystem under --index Junio C Hamano
2015-02-10 22:36     ` [PATCH v4 3/4] apply: do not read from beyond a symbolic link Junio C Hamano
2015-02-10 22:36     ` [PATCH v4 4/4] apply: do not touch a file " Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).