Commit 62251409 by Edward Thomson

fs_path: add length with suffix validation

parent 91246ee5
......@@ -1715,6 +1715,29 @@ bool git_fs_path_str_is_valid_ext(
return true;
}
int git_fs_path_validate_str_length_with_suffix(
git_str *path,
size_t suffix_len)
{
#ifdef GIT_WIN32
size_t utf8_len = git_utf8_char_length(path->ptr, path->size);
size_t total_len;
if (GIT_ADD_SIZET_OVERFLOW(&total_len, utf8_len, suffix_len) ||
total_len > MAX_PATH) {
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'",
(int)path->size, path->ptr);
return -1;
}
#else
GIT_UNUSED(path);
GIT_UNUSED(suffix_len);
#endif
return 0;
}
#ifdef GIT_WIN32
GIT_INLINE(bool) should_validate_longpaths(git_repository *repo)
{
......
......@@ -677,6 +677,10 @@ GIT_INLINE(bool) git_fs_path_str_is_valid(
return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL);
}
extern int git_fs_path_validate_str_length_with_suffix(
git_str *path,
size_t suffix_len);
/**
* Validate an on-disk path, taking into account that it will have a
* suffix appended (eg, `.lock`).
......
......@@ -77,7 +77,7 @@ GIT_INLINE(int) loose_path(
if (git_str_joinpath(out, base, refname) < 0)
return -1;
return git_fs_path_validate_filesystem_with_suffix(out->ptr, out->size,
return git_fs_path_validate_str_length_with_suffix(out,
CONST_STRLEN(".lock"));
}
......
......@@ -240,8 +240,8 @@ GIT_INLINE(int) validate_repo_path(git_str *path)
CONST_STRLEN("objects/pack/pack-.pack.lock") +
GIT_OID_HEXSZ;
return git_fs_path_validate_filesystem_with_suffix(
path->ptr, path->size, suffix_len);
return git_fs_path_validate_str_length_with_suffix(
path, suffix_len);
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment