Skip to content

Commit 7437c0c

Browse files
committed
setup_git_directory(): handle UNC root paths correctly
When working in the root directory of a file share (this is only possible in Git Bash and Powershell, but not in CMD), the current directory is reported without a trailing slash. This is different from Unix and standard Windows directories: both / and C:\ are reported with a trailing slash as current directories. If a Git worktree is located there, Git is not quite prepared for that: while it does manage to find the .git directory/file, it returns as length of the top-level directory's path *one more* than the length of the current directory, and setup_git_directory_gently() would then return an undefined string as prefix. In practice, this undefined string usually points to NUL bytes, and does not cause much harm. Under rare circumstances that are really involved to reproduce (and not reliably so), the reported prefix could be a suffix string of Git's exec path, though. A careful analysis determined that this bug is unlikely to be exploitable, therefore we mark this as a regular bug fix. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d104dfa commit 7437c0c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,
797797
set_git_dir(gitdir);
798798
inside_git_dir = 0;
799799
inside_work_tree = 1;
800-
if (offset == cwd->len)
800+
if (offset >= cwd->len)
801801
return NULL;
802802

803803
/* Make "offset" point past the '/' (already the case for root dirs) */

0 commit comments

Comments
 (0)