Skip to content

Commit a477bff

Browse files
committed
indexer: catch OOM when adding expected OIDs
When adding OIDs to the indexer's map of yet-to-be-seen OIDs to verify that packfiles are complete, we do so by first allocating a new OID and then calling `git_oidmap_set` on it. There was no check for memory allocation errors in place, though, leading to possible segfaults due to trying to copy data to a `NULL` pointer. Verify the result of `git__malloc` with `GIT_ERROR_CHECK_ALLOC` to fix the issue.
1 parent d4fe402 commit a477bff

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/indexer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ static int add_expected_oid(git_indexer *idx, const git_oid *oid)
326326
!git_oidmap_exists(idx->pack->idx_cache, oid) &&
327327
!git_oidmap_exists(idx->expected_oids, oid)) {
328328
git_oid *dup = git__malloc(sizeof(*oid));
329+
GIT_ERROR_CHECK_ALLOC(dup);
329330
git_oid_cpy(dup, oid);
330331
return git_oidmap_set(idx->expected_oids, dup, dup);
331332
}

0 commit comments

Comments
 (0)