repo: handle root paths properly for safe directories

When doing directory name munging to remove trailing slashes, ensure
that we do not remove the trailing slash from the path root, whether
that's '/' or 'C:\'.
This commit is contained in:
Edward Thomson
2024-02-18 07:47:26 -08:00
parent c1734b5ae4
commit e9d5521289

View File

@@ -565,17 +565,18 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload)
} else if (strcmp(entry->value, "*") == 0) {
*data->is_safe = true;
} else {
if (git_str_sets(&data->tmp, entry->value) < 0 ||
git_fs_path_to_dir(&data->tmp) < 0)
if (git_str_sets(&data->tmp, entry->value) < 0)
return -1;
/*
* Ensure that `git_fs_path_to_dir` mutated the
* input path by adding a trailing backslash.
* A trailing backslash on the input is not allowed.
*/
if (strcmp(data->tmp.ptr, entry->value) == 0)
return 0;
if (!git_fs_path_is_root(data->tmp.ptr)) {
/* Input must not have trailing backslash. */
if (!data->tmp.size ||
data->tmp.ptr[data->tmp.size - 1] == '/')
return 0;
if (git_fs_path_to_dir(&data->tmp) < 0)
return -1;
}
test_path = data->tmp.ptr;