summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Strickroth <email@cs-ware.de>2019-06-28 16:49:58 +0200
committerEdward Thomson <ethomson@edwardthomson.com>2022-01-17 22:02:12 -0500
commitf64568ebcb8a5c5be9dcda2a016692edae42a507 (patch)
tree6bafe92a104cdaf8b251d2871de58d672278b0f5
parent7707caaf474eccc1112f62b9d86a6dd240917b58 (diff)
downloadlibgit2-f64568ebcb8a5c5be9dcda2a016692edae42a507.tar.gz
Do not unconditionally remove the last 4 chars of the directory where git.exe was found
Removal of the last 4 chars is only required for Git for Windows installations in order to find the "root" folder of the Git installation. Fixes issue #5127. Signed-off-by: Sven Strickroth <email@cs-ware.de>
-rw-r--r--src/win32/findfile.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index e31ff972e..d5dba8c41 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -93,9 +93,17 @@ static int win32_find_git_in_path(git_str *buf, const wchar_t *gitexe, const wch
continue;
wcscpy(&root.path[root.len], gitexe);
- if (_waccess(root.path, F_OK) == 0 && root.len > 5 && (root.len - 4 + wcslen(subdir) < MAX_PATH)) {
- /* replace "bin\\" or "cmd\\" with subdir */
- wcscpy(&root.path[root.len - 4], subdir);
+ if (!_waccess(root.path, F_OK)) {
+ /* replace "bin\\" or "cmd\\" of a Git for Windows installation with subdir OR append path */
+ if ((root.len > 5 && wcscmp(root.path - 4, L"cmd\\")) || wcscmp(root.path - 4, L"bin\\")) {
+ if (root.len - 4 + wcslen(subdir) >= MAX_PATH)
+ continue;
+ wcscpy(&root.path[root.len - 4], subdir);
+ } else {
+ if (root.len + wcslen(subdir) >= MAX_PATH)
+ continue;
+ wcscat(root.path, subdir);
+ }
win32_path_to_8(buf, root.path);
return 0;