* [PATCH v3] receive-pack: optionally deny case clone refs
@ 2014-06-06 0:52 David Turner
2014-06-06 1:37 ` Duy Nguyen
0 siblings, 1 reply; 3+ messages in thread
From: David Turner @ 2014-06-06 0:52 UTC (permalink / raw)
To: git; +Cc: David Turner
It is possible to have two refs which are the same but for case.
This works great on the case-sensitive filesystems, but not so well on
case-insensitive filesystems. It is fairly typical to have
case-insensitive clients (Macs, say) with a case-sensitive server
(GNU/Linux).
Should a user attempt to pull on a Mac when there are case clone refs
with differing contents, they'll get an error message containing
something like "Ref refs/remotes/origin/lower is at
[sha-of-lowercase-ref] but expected [sha-of-uppercase-ref]....
(unable to update local ref)"
With a case-insensitive git server, if a branch called capital-M
Master (that differs from lowercase-m-master) is pushed, nobody else
can push to (lowercase-m) master until the branch is removed.
Create the option receive.denycaseclonerefs, which checks pushed
refs to ensure that they are not case clones of an existing
ref. This setting is turned on by default if core.ignorecase is
set, but not otherwise.
Signed-off-by: David Turner <dturner@twitter.com>
---
| 6 +++++
| 5 +++--
| 5 +++++
| 27 +++++++++++++++++++++-
| 46 ++++++++++++++++++++++++++++++++++++++
5 files changed, 86 insertions(+), 3 deletions(-)
--git a/Documentation/config.txt b/Documentation/config.txt
index 1932e9b..b24b117 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2053,6 +2053,12 @@ receive.unpackLimit::
especially on slow filesystems. If not set, the value of
`transfer.unpackLimit` is used instead.
+receive.denyCaseCloneRefs::
+ If set to true, git-receive-pack will deny a ref update that creates
+ a ref which is the same but for case as an existing ref. This is
+ useful when clients are on a case-insensitive filesystem, which
+ will cause errors when given refs which differ only in case.
+
receive.denyDeletes::
If set to true, git-receive-pack will deny a ref update that deletes
the ref. Use this to prevent such a ref deletion via a push.
--git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 21cd455..c92c3a6 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -323,8 +323,9 @@ remote rejected::
of the following safety options in effect:
`receive.denyCurrentBranch` (for pushes to the checked out
branch), `receive.denyNonFastForwards` (for forced
- non-fast-forward updates), `receive.denyDeletes` or
- `receive.denyDeleteCurrent`. See linkgit:git-config[1].
+ non-fast-forward updates), `receive.denyDeletes`,
+ `receive.denyCaseCloneRefs` or `receive.denyDeleteCurrent`.
+ See linkgit:git-config[1].
remote failure::
The remote end did not report the successful update of the ref,
--git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index be0858c..ed5ac23 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -31,6 +31,11 @@
[[def_cache]]cache::
Obsolete for: <<def_index,index>>.
+[[def_case_clone]]case clone::
+ Two entities (e.g. filenames or refs) that differ only in case.
+ These can cause problems on case-insensitive filesystems, and
+ Git has machinery to prevent these problems in various cases.
+
[[def_chain]]chain::
A list of objects, where each <<def_object,object>> in the list contains
a reference to its successor (for example, the successor of a
--git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c323081..8530a6c 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -27,6 +27,7 @@ enum deny_action {
static int deny_deletes;
static int deny_non_fast_forwards;
+static int deny_case_clone_refs = DENY_UNCONFIGURED;
static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
static int receive_fsck_objects = -1;
@@ -69,6 +70,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
if (status)
return status;
+ if (strcmp(var, "receive.denycaseclonerefs") == 0) {
+ deny_case_clone_refs = parse_deny_action(var, value);
+ return 0;
+ }
+
if (strcmp(var, "receive.denydeletes") == 0) {
deny_deletes = git_config_bool(var, value);
return 0;
@@ -468,6 +474,22 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
return 0;
}
+static int is_case_clone(const char *refname, const unsigned char *sha1,
+ int flags, void *cb_data)
+{
+ const char *incoming_refname = cb_data;
+ return !strcasecmp(refname, incoming_refname) &&
+ strcmp(refname, incoming_refname);
+}
+
+static int ref_is_denied_case_clone(const char *name)
+{
+ if (!deny_case_clone_refs)
+ return 0;
+
+ return for_each_ref(is_case_clone, (void *) name);
+}
+
static const char *update(struct command *cmd, struct shallow_info *si)
{
const char *name = cmd->ref_name;
@@ -478,7 +500,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
struct ref_lock *lock;
/* only refs/... are allowed */
- if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
+ if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0) ||
+ ref_is_denied_case_clone(name)) {
rp_error("refusing to create funny ref '%s' remotely", name);
return "funny refname";
}
@@ -1171,6 +1194,8 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
die("'%s' does not appear to be a git repository", dir);
git_config(receive_pack_config, NULL);
+ if (deny_case_clone_refs == DENY_UNCONFIGURED)
+ deny_case_clone_refs = ignore_case;
if (0 <= transfer_unpack_limit)
unpack_limit = transfer_unpack_limit;
--git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh
index 0736bcb..a7023dc 100755
--- a/t/t5400-send-pack.sh
+++ b/t/t5400-send-pack.sh
@@ -129,6 +129,52 @@ test_expect_success 'denyNonFastforwards trumps --force' '
test "$victim_orig" = "$victim_head"
'
+test_expect_success 'denyCaseCloneRefs works' '
+ (
+ cd victim &&
+ git config receive.denyCaseCloneRefs true &&
+ git config receive.denyDeletes false
+ ) &&
+ git send-pack ./victim HEAD:refs/heads/caseclone &&
+ orig_ver=$(git rev-parse HEAD) &&
+ test_must_fail git send-pack ./victim HEAD^:refs/heads/CaseClone &&
+ # confirm that this had no effect upstream
+ (
+ cd victim &&
+ ref=$(git for-each-ref --format="%(refname)" refs/heads/CaseClone) &&
+ echo "$ref" | test_must_fail grep -q CaseClone &&
+ remote_ver=$(git rev-parse caseclone) &&
+ test "$orig_ver" = "$remote_ver"
+ ) &&
+ git send-pack ./victim HEAD^:refs/heads/notacaseclone &&
+ test_must_fail git send-pack ./victim :CaseClone &&
+ # confirm that this had no effect upstream
+ (
+ cd victim &&
+ ref=$(git for-each-ref --format="%(refname)" refs/heads/CaseClone) &&
+ echo "$ref" | test_must_fail grep -q CaseClone &&
+ remote_ver=$(git rev-parse caseclone) &&
+ test "$orig_ver" = "$remote_ver"
+ ) &&
+ git send-pack ./victim :caseclone &&
+ # confirm that this took effect upstream
+ (
+ cd victim &&
+ test_must_fail git rev-parse caseclone
+ ) &&
+ # check that we can recreate a branch after deleting a
+ # case-clone of it
+ case_clone_ver=$(git rev-parse HEAD^) &&
+ git send-pack ./victim HEAD^:refs/heads/CaseClone &&
+ (
+ cd victim &&
+ ref=$(git for-each-ref --format="%(refname)" refs/heads/caseclone) &&
+ test_echo "$ref" | test_must_fail grep -q caseclone &&
+ remote_ver=$(git rev-parse CaseClone) &&
+ test "$case_clone_ver" = "$remote_ver"
+ )
+'
+
test_expect_success 'push --all excludes remote-tracking hierarchy' '
mkdir parent &&
(
--
2.0.0.rc1.24.g0588c94.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] receive-pack: optionally deny case clone refs
2014-06-06 0:52 [PATCH v3] receive-pack: optionally deny case clone refs David Turner
@ 2014-06-06 1:37 ` Duy Nguyen
2014-06-06 3:01 ` David Turner
0 siblings, 1 reply; 3+ messages in thread
From: Duy Nguyen @ 2014-06-06 1:37 UTC (permalink / raw)
To: David Turner; +Cc: Git Mailing List, David Turner
On Fri, Jun 6, 2014 at 7:52 AM, David Turner <dturner@twopensource.com> wrote:
> Create the option receive.denycaseclonerefs, which checks pushed
> refs to ensure that they are not case clones of an existing
> ref. This setting is turned on by default if core.ignorecase is
> set, but not otherwise.
Just thinking out loud as I haven't had time to read this patch
carefully, but I wonder if there's a potential performance problem
with ref_is_denied_case_clone(). What if the receiver repo has 60k
refs? Should we use name-hash (or a variant of it)? What if the sender
pushes 60k refs in one go, will ref_is_denied_case_clone check against
existing refs only, or it will cover more and more refs from the 60k
input?
--
Duy
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] receive-pack: optionally deny case clone refs
2014-06-06 1:37 ` Duy Nguyen
@ 2014-06-06 3:01 ` David Turner
0 siblings, 0 replies; 3+ messages in thread
From: David Turner @ 2014-06-06 3:01 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Git Mailing List, David Turner
On Fri, 2014-06-06 at 08:37 +0700, Duy Nguyen wrote:
> On Fri, Jun 6, 2014 at 7:52 AM, David Turner <dturner@twopensource.com> wrote:
> > Create the option receive.denycaseclonerefs, which checks pushed
> > refs to ensure that they are not case clones of an existing
> > ref. This setting is turned on by default if core.ignorecase is
> > set, but not otherwise.
>
> Just thinking out loud as I haven't had time to read this patch
> carefully, but I wonder if there's a potential performance problem
> with ref_is_denied_case_clone(). What if the receiver repo has 60k
> refs? Should we use name-hash (or a variant of it)? What if the sender
> pushes 60k refs in one go, will ref_is_denied_case_clone check against
> existing refs only, or it will cover more and more refs from the 60k
> input?
Good news! The sender can't push 60k refs in one go because that would
require a command-line bigger than ARG_MAX. (Well, OK, this is not
really good news, since of course someone could hack around this, and
since this is minor bug in git that we should probably fix).
I guess this does present a bit of a DOS attack. When I discussed the
previous version of this patch with Junio, I did not think it was a huge
problem, since the the ordinary number of refs pushed is small. But
when I think of it as a DOS, it sounds much worse.
I don't like the idea of creating a hashmap just for this, because
really we need to be storing packed refs in an better on-disk format --
one that allows O(log n) or better access (as has been discussed).
I'll give this some more thought and see if I can come up with a better
solution.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-06-06 3:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-06 0:52 [PATCH v3] receive-pack: optionally deny case clone refs David Turner
2014-06-06 1:37 ` Duy Nguyen
2014-06-06 3:01 ` David Turner
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).