52 lines
1.6 KiB
Diff
52 lines
1.6 KiB
Diff
From eb4c1716cd92bf56f2770653a915d5fc01eab8f3 Mon Sep 17 00:00:00 2001
|
|
From: Edward Thomson <ethomson@edwardthomson.com>
|
|
Date: Sat, 16 Dec 2023 11:19:07 +0000
|
|
Subject: [PATCH] index: correct index has_dir_name check
|
|
|
|
Origin: https://github.com/libgit2/libgit2/commit/eb4c1716cd92bf56f2770653a915d5fc01eab8f3
|
|
|
|
`has_dir_name` is used to check for directory/file collisions,
|
|
and attempts to determine whether the index contains a file with
|
|
a directory name that is a proper subset of the new index entry
|
|
that we're trying to add.
|
|
|
|
To determine directory name, the function would walk the path string
|
|
backwards to identify a `/`, stopping at the end of the string. However,
|
|
the function assumed that the strings did not start with a `/`. If the
|
|
paths contain only a single `/` at the beginning of the string, then the
|
|
function would continue the loop, erroneously, when they should have
|
|
stopped at the first character.
|
|
|
|
Correct the order of the tests to terminate properly.
|
|
|
|
Credit to Michael Rodler (@f0rki) and Amazon AWS Security.
|
|
|
|
---
|
|
vendor/libgit2-sys/libgit2/src/libgit2/index.c | 8 ++++++--
|
|
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/vendor/libgit2-sys/libgit2/src/libgit2/index.c b/vendor/libgit2-sys/libgit2/src/libgit2/index.c
|
|
index 7ebe075..7862273 100644
|
|
--- a/vendor/libgit2-sys/libgit2/src/libgit2/index.c
|
|
+++ b/vendor/libgit2-sys/libgit2/src/libgit2/index.c
|
|
@@ -1155,10 +1155,14 @@ static int has_dir_name(git_index *index,
|
|
size_t len, pos;
|
|
|
|
for (;;) {
|
|
- if (*--slash == '/')
|
|
- break;
|
|
+ slash--;
|
|
+
|
|
if (slash <= entry->path)
|
|
return 0;
|
|
+
|
|
+
|
|
+ if (*slash == '/')
|
|
+ break;
|
|
}
|
|
len = slash - name;
|
|
|
|
--
|
|
2.23.0
|
|
|