Skip to content

Commit 178e1de

Browse files
committed
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 <[email protected]> Analysis-by: David Barr <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent c27e559 commit 178e1de

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

fast-import.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,8 @@ static int tree_content_get(
16401640
n = slash1 - p;
16411641
else
16421642
n = strlen(p);
1643+
if (!n)
1644+
die("Empty path component found in input");
16431645

16441646
if (!root->tree)
16451647
load_tree(root);

t/t9300-fast-import.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,45 @@ test_expect_success \
10871087
M 040000 $subdir file3/
10881088
INPUT_END'
10891089

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+
10901129
test_expect_success \
10911130
'N: copy to root by id and modify' \
10921131
'echo "hello, world" >expect.foo &&

0 commit comments

Comments
 (0)