From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Josh Boyer <jwboyer@fedoraproject.org>,
"Linux-Kernel@Vger. Kernel. Org" <linux-kernel@vger.kernel.org>,
twaugh@redhat.com, Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] apply: refuse touching a file beyond symlink
Date: Fri, 30 Jan 2015 15:07:32 -0500 [thread overview]
Message-ID: <20150130200731.GC30738@peff.net> (raw)
In-Reply-To: <xmqq61bocao1.fsf@gitster.dls.corp.google.com>
On Fri, Jan 30, 2015 at 11:48:14AM -0800, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> >> + if (!patch->is_delete && path_is_beyond_symlink(patch->new_name))
> >> + return error(_("affected file '%s' is beyond a symbolic link"),
> >> + patch->new_name);
> >
> > Why does this not kick in when deleting a file? If it is not OK to
> > add across a symlink, why is it OK to delete?
>
> Hmph, adding
>
> if (patch->is_delete && path_is_beyond_symlink(patch->old_name))
> return error(_("deleted file '%s' is beyond a symlink"),
> patch->old_name);
>
> seems to break t4114.11, which wants to apply this patch to a tree
> that does not have a symbolic link but a directory at 'foo/'.
>
> diff --git a/foo b/foo
> new file mode 120000
> index 0000000..ba0e162
> --- /dev/null
> +++ b/foo
> @@ -0,0 +1 @@
> +bar
> \ No newline at end of file
> diff --git a/foo/baz b/foo/baz
> deleted file mode 100644
> index 682c76b..0000000
> --- a/foo/baz
> +++ /dev/null
> @@ -1 +0,0 @@
> -if only I knew
Hrm. That only works in the current code because we apply the deletion
in the directory (and then clean up the now-empty directory) first. So I
think you would need to check the paths progressively as you apply them,
since those other parts of the diff "haven't happened yet".
If we take deletion as one phase and addition as another, I think you
could get away with:
diff --git a/builtin/apply.c b/builtin/apply.c
index f5491cd..12c9d8e 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -3549,7 +3549,7 @@ static int check_to_create(const char *new_name, int ok_if_exists)
return 0;
}
-static int path_is_beyond_symlink(const char *name_)
+static int path_is_beyond_symlink(const char *name_, int check_table)
{
struct strbuf name = STRBUF_INIT;
@@ -3562,7 +3562,8 @@ static int path_is_beyond_symlink(const char *name_)
if (!name.len)
break;
name.buf[name.len] = '\0';
- previous = in_fn_table(name.buf);
+
+ previous = check_table ? in_fn_table(name.buf) : NULL;
if (previous) {
if (!was_deleted(previous) &&
!to_be_deleted(previous) &&
@@ -3676,9 +3677,12 @@ static int check_patch(struct patch *patch)
}
}
- if (!patch->is_delete && path_is_beyond_symlink(patch->new_name))
+ if (!patch->is_delete && path_is_beyond_symlink(patch->new_name, 1))
return error(_("affected file '%s' is beyond a symbolic link"),
patch->new_name);
+ if (patch->is_delete && path_is_beyond_symlink(patch->old_name, 0))
+ return error(_("affected file '%s' is beyond a symbolic link"),
+ patch->old_name);
if (apply_data(patch, &st, ce) < 0)
return error(_("%s: patch does not apply"), name);
but I suspect we could construct a case that depends more closely on the
order of application. E.g., a patch that does:
1. add foo as a symlink
2. add file foo/bar
is definitely wrong. But is:
1. add file foo/bar
2. add foo as a symlink
does not technically fall afoul of the symlink rules. It is a _bogus_
patch, of course, because the second part will get a D/F conflict. I am
not sure if there are any legitimate patches that could run into this
ordering problem, but even without it, it smells a bit funny to complain
for the wrong reason.
Looking at the code, though, it seems like we should be doing these
checks progressively as we add entries to the fn_table. So that is doing
the right thing. It is only the deletion re-ordering that trips us up.
Can we reorder all deletions before all additions before calling
check_patch on each?
-Peff
next prev parent reply other threads:[~2015-01-30 20:07 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-26 16:29 patch-2.7.3 no longer applies relative symbolic link patches Josh Boyer
2015-01-26 16:32 ` Josh Boyer
2015-01-26 20:44 ` Linus Torvalds
2015-01-26 21:01 ` David Kastrup
2015-01-26 21:07 ` Josh Boyer
2015-01-26 21:30 ` Linus Torvalds
2015-01-26 21:35 ` Junio C Hamano
2015-01-26 21:50 ` Linus Torvalds
2015-01-27 15:47 ` Andreas Gruenbacher
2015-01-31 21:27 ` Andreas Gruenbacher
2015-01-26 22:15 ` Josh Boyer
2015-01-27 3:27 ` Junio C Hamano
2015-01-27 20:39 ` Junio C Hamano
2015-01-29 6:05 ` Junio C Hamano
2015-01-29 6:34 ` Junio C Hamano
2015-01-29 20:45 ` [PATCH] apply: refuse touching a file beyond symlink Junio C Hamano
2015-01-29 22:15 ` Stefan Beller
2015-01-29 23:48 ` [PATCH 2/1] apply: reject input that touches outside $cwd Junio C Hamano
2015-01-30 18:24 ` Jeff King
2015-01-30 19:07 ` Junio C Hamano
2015-01-30 19:16 ` Jeff King
2015-01-30 9:04 ` [PATCH] apply: refuse touching a file beyond symlink Christian Couder
2015-01-30 18:11 ` Jeff King
2015-01-30 19:42 ` Junio C Hamano
2015-01-30 19:46 ` Jeff King
2015-01-30 19:48 ` Junio C Hamano
2015-01-30 20:07 ` Jeff King [this message]
2015-01-30 20:32 ` Junio C Hamano
2015-01-30 20:11 ` Junio C Hamano
2015-01-30 20:16 ` Jeff King
2015-01-30 20:20 ` Junio C Hamano
2015-01-30 20:48 ` Jeff King
2015-01-30 21:10 ` Junio C Hamano
2015-01-30 21:50 ` Junio C Hamano
2015-01-27 15:26 ` patch-2.7.3 no longer applies relative symbolic link patches Andreas Gruenbacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150130200731.GC30738@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jwboyer@fedoraproject.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=twaugh@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).