Commit 21981f28627b65d43590166b6a1782bb101dcddd

panda 2021-02-16T13:43:09

index: Check git_vector_dup error in write_entries If allocating case_sorted.contents fails, git_vector_sort will segfault.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/index.c b/src/index.c
index 7ebe075..263f8e5 100644
--- a/src/index.c
+++ b/src/index.c
@@ -2868,7 +2868,9 @@ static int write_entries(git_index *index, git_filebuf *file)
 	/* If index->entries is sorted case-insensitively, then we need
 	 * to re-sort it case-sensitively before writing */
 	if (index->ignore_case) {
-		git_vector_dup(&case_sorted, &index->entries, git_index_entry_cmp);
+		if ((error = git_vector_dup(&case_sorted, &index->entries, git_index_entry_cmp)) < 0)
+			return error;
+
 		git_vector_sort(&case_sorted);
 		entries = &case_sorted;
 	} else {