Skip to content

Commit c0558c6

Browse files
committed
tests: rebase::submodule: verify initialization method calls
Some return codes for functions which may fail are not being checked in `test_rebase_submodule__initialize`. This may lead us to not notice errors when initializing the environment and would possibly result in either memory corruption or segfaults as soon as any of the initialization steps fails. Fix this by wrapping these function calls into `cl_git_pass`.
1 parent 4f4bc57 commit c0558c6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/rebase/submodule.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ void test_rebase_submodule__initialize(void)
2828

2929
rewrite_gitmodules(git_repository_workdir(repo));
3030

31-
git_submodule_set_url(repo, "my-submodule", git_repository_path(repo));
31+
cl_git_pass(git_submodule_set_url(repo, "my-submodule", git_repository_path(repo)));
3232

3333
/* We have to commit the rewritten .gitmodules file */
34-
git_repository_index(&index, repo);
35-
git_index_add_bypath(index, ".gitmodules");
36-
git_index_write_tree(&tree_oid, index);
37-
git_index_free(index);
34+
cl_git_pass(git_repository_index(&index, repo));
35+
cl_git_pass(git_index_add_bypath(index, ".gitmodules"));
36+
cl_git_pass(git_index_write_tree(&tree_oid, index));
3837

3938
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
4039

41-
git_repository_head(&master_ref, repo);
40+
cl_git_pass(git_repository_head(&master_ref, repo));
4241
cl_git_pass(git_commit_lookup(&parent, repo, git_reference_target(master_ref)));
4342

4443
cl_git_pass(git_commit_create_v(&commit_id, repo, git_reference_name(master_ref), signature, signature, NULL, "Fixup .gitmodules", tree, 1, parent));
4544

4645
/* And a final reset, for good measure */
47-
git_object_lookup(&obj, repo, &commit_id, GIT_OBJ_COMMIT);
46+
cl_git_pass(git_object_lookup(&obj, repo, &commit_id, GIT_OBJ_COMMIT));
4847
cl_git_pass(git_reset(repo, obj, GIT_RESET_HARD, &opts));
4948

49+
git_index_free(index);
5050
git_object_free(obj);
5151
git_commit_free(parent);
5252
git_reference_free(master_ref);

0 commit comments

Comments
 (0)