mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 01:20:53 +00:00
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.
This commit is contained in:
parent
4d384d6bbe
commit
225cb8809e
@ -104,7 +104,7 @@ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *r
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_id && git_oid_cmp(current_id, git_array_get(*parents, 0))) {
|
if (current_id && (parents->size == 0 || git_oid_cmp(current_id, git_array_get(*parents, 0)))) {
|
||||||
giterr_set(GITERR_OBJECT, "failed to create commit: current tip is not the first parent");
|
giterr_set(GITERR_OBJECT, "failed to create commit: current tip is not the first parent");
|
||||||
error = GIT_EMODIFIED;
|
error = GIT_EMODIFIED;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
Loading…
Reference in New Issue
Block a user