From c27e559da5b26faa31858fe6dc5492d4f605b867 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 9 Mar 2012 21:20:34 -0600 Subject: fast-import: leakfix for 'ls' of dirty trees When the chosen directory has changed since it was last written to pack, "tree_content_get" makes a deep copy of its content to scribble on while computing the tree name, which we forgot to free. This leak has been present since the 'ls' command was introduced in v1.7.5-rc0~3^2~33 (fast-import: add 'ls' command, 2010-12-02). Signed-off-by: Jonathan Nieder --- fast-import.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fast-import.c b/fast-import.c index 6c37b8400..fff285cd0 100644 --- a/fast-import.c +++ b/fast-import.c @@ -2987,6 +2987,8 @@ static void parse_ls(struct branch *b) store_tree(&leaf); print_ls(leaf.versions[1].mode, leaf.versions[1].sha1, p); + if (leaf.tree) + release_tree_content_recursive(leaf.tree); if (!b || root != &b->branch_tree) release_tree_entry(root); } -- cgit v1.2.1 From 178e1deaae33f879ea687e85ac72455b3072b0d8 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 9 Mar 2012 22:07:22 -0600 Subject: fast-import: don't allow 'ls' of path with empty components As the fast-import manual explains: The value of 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. Reported-by: Andrew Sayers Analysis-by: David Barr Signed-off-by: Jonathan Nieder --- 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 fff285cd0..47f61f3cb 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 6b1ba6c85..2cd0f0614 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -1087,6 +1087,45 @@ test_expect_success \ M 040000 $subdir file3/ 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 < $GIT_COMMITTER_DATE + data < $GIT_COMMITTER_DATE + data <expect.foo && -- cgit v1.2.1