git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: David Barr <davidbarr@google.com>,
	Git Mailing List <git@vger.kernel.org>,
	Andrew Sayers <andrew-git@pileofstuff.org>,
	Dmitry Ivankov <divanorama@gmail.com>,
	Sverre Rabbelier <srabbelier@gmail.com>
Subject: [PATCH maint-1.7.6] fast-import: don't allow 'ls' of path with empty components
Date: Fri, 9 Mar 2012 22:00:49 -0600	[thread overview]
Message-ID: <20120310040049.GC3008@burratino> (raw)
In-Reply-To: <20120310031228.GA3008@burratino>

As the fast-import manual explains:

	The value of <path> must be in canonical form. That is it must
	not:
	. contain an empty directory component (e.g. foo//bar is invalid),
	. end with a directory separator (e.g. foo/ is invalid),
	. start with a directory separator (e.g. /foo is invalid),

Unfortunately the "ls" command accepts these invalid syntaxes and
responds by declaring that the indicated path is missing.  This is too
subtle and causes importers to silently misbehave; better to error out
so the operator knows what's happening.

The C, R, and M commands already error out for such paths.

Based on initial analysis by David Barr.

Reported-by: Andrew Sayers <andrew-git@pileofstuff.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Also against on 8dc6a373d (fast-import: add 'ls' command, 2010-12-02).

 fast-import.c          |    2 ++
 t/t9300-fast-import.sh |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/fast-import.c b/fast-import.c
index fff285cd..47f61f3c 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1640,6 +1640,8 @@ static int tree_content_get(
 		n = slash1 - p;
 	else
 		n = strlen(p);
+	if (!n)
+		die("Empty path component found in input");
 
 	if (!root->tree)
 		load_tree(root);
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 6b1ba6c8..2cd0f061 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -1088,6 +1088,45 @@ test_expect_success \
 	INPUT_END'
 
+test_expect_success \
+	'N: reject foo/ syntax in copy source' \
+	'test_must_fail git fast-import <<-INPUT_END
+	commit refs/heads/N5C
+	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+	data <<COMMIT
+	copy with invalid syntax
+	COMMIT
+
+	from refs/heads/branch^0
+	C file2/ file3
+	INPUT_END'
+
+test_expect_success \
+	'N: reject foo/ syntax in rename source' \
+	'test_must_fail git fast-import <<-INPUT_END
+	commit refs/heads/N5D
+	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+	data <<COMMIT
+	rename with invalid syntax
+	COMMIT
+
+	from refs/heads/branch^0
+	R file2/ file3
+	INPUT_END'
+
+test_expect_success \
+	'N: reject foo/ syntax in ls argument' \
+	'test_must_fail git fast-import <<-INPUT_END
+	commit refs/heads/N5E
+	committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+	data <<COMMIT
+	copy with invalid syntax
+	COMMIT
+
+	from refs/heads/branch^0
+	ls "file2/"
+	INPUT_END'
+
 test_expect_success \
 	'N: copy to root by id and modify' \
 	'echo "hello, world" >expect.foo &&
 	 echo hello >expect.bar &&
-- 
1.7.9.2

  parent reply	other threads:[~2012-03-10  4:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-08  3:13 [BUG] fast-import: ls command on commit root returns missing (was: Bug in svn-fe: copying the root directory acts as if it's an empty directory) David Barr
2012-03-08  5:30 ` [PATCH] fast-import: fix ls command with empty path David Barr
2012-03-08  7:09   ` Jonathan Nieder
2012-03-08 15:29     ` Sverre Rabbelier
2012-03-08 16:39     ` Junio C Hamano
2012-03-08 17:33       ` Dmitry Ivankov
2012-03-08 19:32         ` Jonathan Nieder
2012-03-10  9:48         ` Jonathan Nieder
2012-03-08 18:15       ` Jonathan Nieder
2012-03-10  3:12       ` Jonathan Nieder
2012-03-10  3:20         ` [PATCH maint-1.7.6] fast-import: leakfix for 'ls' of dirty trees Jonathan Nieder
2012-03-10  4:00         ` Jonathan Nieder [this message]
2012-03-10  4:30         ` [PULL maint] two fast-import "ls" fixes Jonathan Nieder
2012-03-10  7:00         ` [NON-PATCH] vcs-svn: avoid 'ls' and filedelete with empty path Jonathan Nieder
2013-06-21 16:33         ` [PATCH] fast-import: fix ls command " Dave Abrahams
2012-03-08 20:27   ` [PATCH v2 0/2] " Jonathan Nieder
2012-03-08 20:31     ` [PATCH 1/2] fast-import: plug leak of dirty trees in 'ls' command Jonathan Nieder
2012-03-08 20:33     ` [PATCH 2/2] fast-import: teach ls command to accept empty path Jonathan Nieder
2012-03-09  4:28       ` David Barr
2012-03-09  9:29         ` Jonathan Nieder
2012-03-10  8:53   ` [PATCH v3] fast-import: allow 'ls' and filecopy to read the root Jonathan Nieder
2012-03-10  9:01     ` Jonathan Nieder
2012-03-10  9:18     ` [PATCH 2/1] fixup! " Jonathan Nieder

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=20120310040049.GC3008@burratino \
    --to=jrnieder@gmail.com \
    --cc=andrew-git@pileofstuff.org \
    --cc=davidbarr@google.com \
    --cc=divanorama@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=srabbelier@gmail.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.
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).