Skip to content

Commit 13deb87

Browse files
committed
index: fix NULL pointer access in index_remove_entry
When removing an entry from the index by its position, we first retrieve the position from the index's entries and then try to remove the retrieved value from the index map with `DELETE_IN_MAP`. When `index_remove_entry` returns `NULL` we try to feed it into the `DELETE_IN_MAP` macro, which will unconditionally call `idxentry_hash` and then happily dereference the `NULL` entry pointer. Fix the issue by not passing a `NULL` entry into `DELETE_IN_MAP`.
1 parent 7d02019 commit 13deb87

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/index.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,11 @@ static int index_remove_entry(git_index *index, size_t pos)
505505
int error = 0;
506506
git_index_entry *entry = git_vector_get(&index->entries, pos);
507507

508-
if (entry != NULL)
508+
if (entry != NULL) {
509509
git_tree_cache_invalidate_path(index->tree, entry->path);
510+
DELETE_IN_MAP(index, entry);
511+
}
510512

511-
DELETE_IN_MAP(index, entry);
512513
error = git_vector_remove(&index->entries, pos);
513514

514515
if (!error) {

0 commit comments

Comments
 (0)