Skip to content

Commit bf10cf7

Browse files
mhaggergitster
authored andcommitted
safe_create_leading_directories(): split on first of multiple slashes
If the input path has multiple slashes between path components (e.g., "foo//bar"), then the old code was breaking the path at the last slash, not the first one. So in the above example, the second slash was overwritten with NUL, resulting in the parent directory being sought as "foo/". When stat() is called on "foo/", it fails with ENOTDIR if "foo" exists but is not a directory. This caused the wrong path to be taken in the subsequent logic. So instead, split path components at the first intercomponent slash rather than the last one. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26c8ae2 commit bf10cf7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sha1_file.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ int safe_create_leading_directories(char *path)
115115

116116
if (!slash)
117117
break;
118-
while (*(slash + 1) == '/')
119-
slash++;
118+
120119
next_component = slash + 1;
120+
while (*next_component == '/')
121+
next_component++;
121122
if (!*next_component)
122123
break;
123124

0 commit comments

Comments
 (0)