fast-import: don't allow 'ls' of path with empty components

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. Reported-by: Andrew Sayers <andrew-git@pileofstuff.org> Analysis-by: David Barr <davidbarr@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

Jonathan Nieder committed Mar 9, 2012 at 22:07 UTC 178e1deaae33f879ea687e85ac72455b3072b0d8
2 files changed +41
fast-import.c
+2
@@ -1640,6 +1640,8 @@ static int tree_content_get(
1640 n = slash1 - p;
1641 else
1642 n = strlen(p);
1643 + if (!n)
1644 + die("Empty path component found in input");
1645
1646 if (!root->tree)
1647 load_tree(root);
t/t9300-fast-import.sh
+39
@@ -1087,6 +1087,45 @@ test_expect_success \
1087 M 040000 $subdir file3/
1088 INPUT_END'
1089
1090 +test_expect_success \
1091 + 'N: reject foo/ syntax in copy source' \
1092 + 'test_must_fail git fast-import <<-INPUT_END
1093 + commit refs/heads/N5C
1094 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1095 + data <<COMMIT
1096 + copy with invalid syntax
1097 + COMMIT
1098 +
1099 + from refs/heads/branch^0
1100 + C file2/ file3
1101 + INPUT_END'
1102 +
1103 +test_expect_success \
1104 + 'N: reject foo/ syntax in rename source' \
1105 + 'test_must_fail git fast-import <<-INPUT_END
1106 + commit refs/heads/N5D
1107 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1108 + data <<COMMIT
1109 + rename with invalid syntax
1110 + COMMIT
1111 +
1112 + from refs/heads/branch^0
1113 + R file2/ file3
1114 + INPUT_END'
1115 +
1116 +test_expect_success \
1117 + 'N: reject foo/ syntax in ls argument' \
1118 + 'test_must_fail git fast-import <<-INPUT_END
1119 + commit refs/heads/N5E
1120 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1121 + data <<COMMIT
1122 + copy with invalid syntax
1123 + COMMIT
1124 +
1125 + from refs/heads/branch^0
1126 + ls "file2/"
1127 + INPUT_END'
1128 +
1129 test_expect_success \
1130 'N: copy to root by id and modify' \
1131 'echo "hello, world" >expect.foo &&