Commit aca3f701 by Edward Thomson

path: safely cast path calculation

parent f1d73189
...@@ -160,7 +160,13 @@ int git_path_dirname_r(git_buf *buffer, const char *path) ...@@ -160,7 +160,13 @@ int git_path_dirname_r(git_buf *buffer, const char *path)
while (endp > path && *endp == '/') while (endp > path && *endp == '/')
endp--; endp--;
if ((len = win32_prefix_length(path, endp - path + 1)) > 0) { if (endp - path + 1 > INT_MAX) {
git_error_set(GIT_ERROR_INVALID, "path too long");
len = -1;
goto Exit;
}
if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
is_prefix = 1; is_prefix = 1;
goto Exit; goto Exit;
} }
...@@ -180,7 +186,13 @@ int git_path_dirname_r(git_buf *buffer, const char *path) ...@@ -180,7 +186,13 @@ int git_path_dirname_r(git_buf *buffer, const char *path)
endp--; endp--;
} while (endp > path && *endp == '/'); } while (endp > path && *endp == '/');
if ((len = win32_prefix_length(path, endp - path + 1)) > 0) { if (endp - path + 1 > INT_MAX) {
git_error_set(GIT_ERROR_INVALID, "path too long");
len = -1;
goto Exit;
}
if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
is_prefix = 1; is_prefix = 1;
goto Exit; goto Exit;
} }
......
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