Skip to content

Commit 225cb88

Browse files
author
John Haley
committed
Fix git_commit_create for an initial commit
When calling `git_commit_create` with an empty array of `parents` and `parent_count == 0` the call will segfault at https://github.com/libgit2/libgit2/blob/master/src/commit.c#L107 when it's trying to compare `current_id` to a null parent oid. This just puts in a check to stop that segfault.
1 parent 4d384d6 commit 225cb88

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *r
104104
i++;
105105
}
106106

107-
if (current_id && git_oid_cmp(current_id, git_array_get(*parents, 0))) {
107+
if (current_id && (parents->size == 0 || git_oid_cmp(current_id, git_array_get(*parents, 0)))) {
108108
giterr_set(GITERR_OBJECT, "failed to create commit: current tip is not the first parent");
109109
error = GIT_EMODIFIED;
110110
goto on_error;

0 commit comments

Comments
 (0)