8000 Merge branch 'safedir' · russell/libgit2@25e2b9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 25e2b9d

Browse files
committed
Merge branch 'safedir'
2 parents ff58b16 + 516749f commit 25e2b9d

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/libgit2/repository.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,18 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload)
566566
} else {
567567
const char *test_path = entry->value;
568568

569+
if (git_str_sets(&data->tmp, test_path) < 0 ||
570+
git_fs_path_to_dir(&data->tmp) < 0)
571+
return -1;
572+
573+
/*
574+
* Ensure that `git_fs_path_to_dir` mutated the
575+
* input path by adding a trailing backslash.
576+
* A trailing backslash on the input is not allowed.
577+
*/
578+
if (strcmp(data->tmp.ptr, test_path) == 0)
579+
return 0;
580+
569581
#ifdef GIT_WIN32
570582
/*
571583
* Git for Windows does some truly bizarre things with
@@ -596,8 +608,7 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload)
596608
test_path++;
597609
#endif
598610

599-
if (git_fs_path_prettify_dir(&data->tmp, test_path, NULL) == 0 &&
600-
strcmp(data->tmp.ptr, data->repo_path) == 0)
611+
if (strcmp(data->tmp.ptr, data->repo_path) == 0)
601612
*data->is_safe = true;
602613
}
603614

tests/libgit2/repo/open.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,25 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
555555

556556
git_str_joinpath(&config_filename, config_path.ptr, ".gitconfig");
557557

558+
/* Test with incorrect exception (slash at the end) */
559+
git_str_printf(&config_data,
560+
"[foo]\n" \
561+
"\tbar = Foobar\n" \
562+
"\tbaz = Baz!\n" \
563+
"[safe]\n" \
564+
"\tdirectory = /non/existent/path\n" \
565+
"\tdirectory = /\n" \
566+
"\tdirectory = c:\\\\temp\n" \
567+
"\tdirectory = %s/%s/\n" \
568+
"\tdirectory = /tmp\n" \
569+
"[bar]\n" \
570+
"\tfoo = barfoo\n",
571+
clar_sandbox_path(), "empty_standard_repo");
572+
cl_git_rewritefile(config_filename.ptr, config_data.ptr);
573+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
574+
575+
/* Test with correct exception */
576+
git_str_clear(&config_data);
558577
git_str_printf(&config_data,
559578
"[foo]\n" \
560579
"\tbar = Foobar\n" \

0 commit comments

Comments
 (0)
0