summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/libgit2/libgit2/CVE-2024-24577.patch
blob: 3469f9d099de22bf693d5c7757e3da9a51542c3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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

`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.

CVE: CVE-2024-24577

Upstream-Status: Backport [https://github.com/libgit2/libgit2/commit/eb4c1716cd92bf56f2770653a915d5fc01eab8f3]

Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com>
---
 src/index.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/index.c b/src/index.c
index aa97c6421..e8ff82e1a 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1148,10 +1148,13 @@ 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.40.0