From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] builtin-mv: minimum fix to avoid losing files
Date: Mon, 04 Feb 2008 00:09:56 -0800 [thread overview]
Message-ID: <7vhcgpkuqz.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7v3as9mce7.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Sun, 03 Feb 2008 23:03:28 -0800")
An incorrect command "git mv subdir /outer/space" threw the
subdirectory to outside of the repository and then noticed that
/outer/space/subdir/ would be outside of the repository. The
error checking is backwards.
This fixes the issue by being careful about use of the return
value of get_pathspec(). Since the implementation already has
handcrafted loop to munge each path on the command line, we use
prefix_path() instead.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* This minimally fixes the issue and applies on top of the
"setup: sanitize absolute and funny paths in get_pathspec()"
patch I showed during the rc freeze.
Dscho CC'ed as he owns the largest number of lines in this
source file.
builtin-mv.c | 6 +++++-
t/t7001-mv.sh | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/builtin-mv.c b/builtin-mv.c
index 94f6dd2..68aa2a6 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -19,6 +19,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
int count, int base_name)
{
int i;
+ int len = prefix ? strlen(prefix) : 0;
const char **result = xmalloc((count + 1) * sizeof(const char *));
memcpy(result, pathspec, count * sizeof(const char *));
result[count] = NULL;
@@ -32,8 +33,11 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
if (last_slash)
result[i] = last_slash + 1;
}
+ result[i] = prefix_path(prefix, len, result[i]);
+ if (!result[i])
+ exit(1); /* error already given */
}
- return get_pathspec(prefix, result);
+ return result;
}
static void show_list(const char *label, struct path_list *list)
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index b1243b4..fa382c5 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -118,4 +118,42 @@ test_expect_success "Sergey Vlasov's test case" '
git mv ab a
'
+test_expect_success 'absolute pathname' '(
+
+ rm -fr mine &&
+ mkdir mine &&
+ cd mine &&
+ test_create_repo one &&
+ cd one &&
+ mkdir sub &&
+ >sub/file &&
+ git add sub/file &&
+
+ git mv sub "$(pwd)/in" &&
+ ! test -d sub &&
+ test -d in &&
+ git ls-files --error-unmatch in/file
+
+
+)'
+
+test_expect_success 'absolute pathname outside should fail' '(
+
+ rm -fr mine &&
+ mkdir mine &&
+ cd mine &&
+ out=$(pwd) &&
+ test_create_repo one &&
+ cd one &&
+ mkdir sub &&
+ >sub/file &&
+ git add sub/file &&
+
+ ! git mv sub "$out/out" &&
+ test -d sub &&
+ ! test -d ../in &&
+ git ls-files --error-unmatch sub/file
+
+)'
+
test_done
--
1.5.4.18.gd0b8
next prev parent reply other threads:[~2008-02-04 8:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-04 7:03 [PATCH] fix misuse of prefix_path() Junio C Hamano
2008-02-04 8:09 ` Junio C Hamano [this message]
2008-02-04 18:08 ` [PATCH] builtin-mv: minimum fix to avoid losing files Johannes Schindelin
2008-02-04 11:13 ` [PATCH] fix misuse of prefix_path() Johannes Sixt
2008-02-05 8:17 ` [PATCH] Fix " Johannes Sixt
2008-02-05 9:45 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vhcgpkuqz.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).