From: Thomas Rast <trast@student.ethz.ch>
To: <git@vger.kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] Handle double slashes in make_relative_path()
Date: Fri, 22 Jan 2010 01:07:31 +0100 [thread overview]
Message-ID: <379d55c6a4110736aadb8ace3b050de879a9deab.1264118830.git.trast@student.ethz.ch> (raw)
If you say
git --git-dir=/some//path --work-tree=/some/ add <somefile>
then setup_work_tree() will call into make_relative_path() with
abs="/some//path" and base="/some". (Note how the latter has already
lost its trailing slash. One unfortunate user managed to trigger this
because his $HOME ended in a slash.)
This means that when checking whether 'abs' is a path under 'base', we
need to skip *two* slashes where the previous code only accounted for
one. Fix it to handle an arbitrary number of slashes at that
position.
Noticed-by: eldenz on freenode
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
path.c | 6 +++---
t/t1501-worktree.sh | 6 ++++++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/path.c b/path.c
index 2ec950b..a195bab 100644
--- a/path.c
+++ b/path.c
@@ -400,10 +400,10 @@ int set_shared_perm(const char *path, int mode)
baselen = strlen(base);
if (prefixcmp(abs, base))
return abs;
- if (abs[baselen] == '/')
- baselen++;
- else if (base[baselen - 1] != '/')
+ if (abs[baselen] != '/' && base[baselen - 1] != '/')
return abs;
+ while (abs[baselen] == '/')
+ baselen++;
strcpy(buf, abs + baselen);
return buf;
}
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index 74e6443..9df3012 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -189,4 +189,10 @@ test_expect_success 'absolute pathspec should fail gracefully' '
)
'
+test_expect_success 'make_relative_path handles double slashes in GIT_DIR' '
+ : > dummy_file
+ echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file &&
+ git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file
+'
+
test_done
--
1.6.6.1.532.g594fe
next reply other threads:[~2010-01-22 0:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-22 0:07 Thomas Rast [this message]
2010-01-22 1:40 ` [PATCH] Handle double slashes in make_relative_path() Junio C Hamano
2010-01-22 3:05 ` Junio C Hamano
2010-01-22 8:36 ` Johannes Sixt
2010-01-23 11:40 ` Robin Rosenberg
2010-01-23 13:09 ` Johannes Sixt
2010-01-23 13:48 ` Robin Rosenberg
2010-01-23 19:00 ` Johannes Sixt
2010-01-23 20:04 ` Junio C Hamano
2010-01-23 20:14 ` Junio C Hamano
2010-01-23 20:41 ` Johannes Sixt
2010-01-23 21:01 ` Sverre Rabbelier
2010-01-24 13:57 ` Thomas Rast
2010-01-24 19:04 ` Bernhard R. Link
2010-01-24 20:05 ` Junio C Hamano
2010-01-24 16:44 ` Johannes Sixt
2010-01-24 18:31 ` Junio C Hamano
2010-01-25 1:06 ` Robin Rosenberg
2010-01-22 21:11 ` Thomas Rast
2010-01-22 23:35 ` Junio C Hamano
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=379d55c6a4110736aadb8ace3b050de879a9deab.1264118830.git.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=torvalds@linux-foundation.org \
/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).