git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH maint-1.7.6] fast-import: don't allow 'ls' of path with empty components

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 10, 2012, 04:00 UTC
Message-ID
<20120310040049.GC3008@burratino>
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
Previous: Jonathan NiederNext: Jonathan Nieder
Message 12 of 23 in “[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)”
  1. David BarrMar 8, 2012
  2. fast-import: fix ls command with empty pathDavid Barr, Mar 8, 2012
  3. Jonathan NiederMar 8, 2012
  4. Sverre RabbelierMar 8, 2012
  5. Junio C HamanoMar 8, 2012
  6. Dmitry IvankovMar 8, 2012
  7. Jonathan NiederMar 8, 2012
  8. Jonathan NiederMar 10, 2012
  9. Jonathan NiederMar 8, 2012
  10. Jonathan NiederMar 10, 2012
  11. fast-import: leakfix for 'ls' of dirty treesJonathan Nieder, Mar 10, 2012
  12. fast-import: don't allow 'ls' of path with empty componentsJonathan Nieder, Mar 10, 2012
  13. [PULL maint] two fast-import "ls" fixesJonathan Nieder, Mar 10, 2012
  14. vcs-svn: avoid 'ls' and filedelete with empty pathJonathan Nieder, Mar 10, 2012
  15. Dave AbrahamsJun 21, 2013
  16. 0/2 Re: fast-import: fix ls command with empty pathJonathan Nieder, Mar 8, 2012
  17. 1/2 fast-import: plug leak of dirty trees in 'ls' commandJonathan Nieder, Mar 8, 2012
  18. 2/2 fast-import: teach ls command to accept empty pathJonathan Nieder, Mar 8, 2012
  19. David BarrMar 9, 2012
  20. Jonathan NiederMar 9, 2012
  21. fast-import: allow 'ls' and filecopy to read the rootJonathan Nieder, Mar 10, 2012
  22. Jonathan NiederMar 10, 2012
  23. 2/1 fixup! fast-import: allow 'ls' and filecopy to read the rootJonathan Nieder, Mar 10, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.