Commit 90450d8825e01e2deb24e0f9bd244a9efe243528

Patrick Steinhardt 2020-02-07T12:10:12

indexer: check return code of `git_hash_ctx_init` Initialization of the hashing context may fail on some systems, most notably on Win32 via the legacy hashing context. As such, we need to always check the error code of `git_hash_ctx_init`, which is not done when creating a new indexer. Fix the issue by adding checks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/indexer.c b/src/indexer.c
index 717549f..68fdd85 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -150,11 +150,11 @@ int git_indexer_new(
 	idx->progress_cb = opts.progress_cb;
 	idx->progress_payload = opts.progress_cb_payload;
 	idx->mode = mode ? mode : GIT_PACK_FILE_MODE;
-	git_hash_ctx_init(&idx->hash_ctx);
-	git_hash_ctx_init(&idx->trailer);
 	git_buf_init(&idx->entry_data, 0);
 
-	if ((error = git_oidmap_new(&idx->expected_oids)) < 0)
+	if ((error = git_hash_ctx_init(&idx->hash_ctx)) < 0 ||
+	    (error = git_hash_ctx_init(&idx->trailer)) < 0 ||
+	    (error = git_oidmap_new(&idx->expected_oids)) < 0)
 		goto cleanup;
 
 	idx->do_verify = opts.verify;