Skip to content

commit: verify objects exist in git_commit_with_signature#5289

Merged
ethomson merged 2 commits into
masterfrom
cmn/create-with-signature-verification
Nov 1, 2019
Merged

commit: verify objects exist in git_commit_with_signature#5289
ethomson merged 2 commits into
masterfrom
cmn/create-with-signature-verification

Conversation

@carlosmn
Copy link
Copy Markdown
Member

There can be a significant difference between the system where we created the
buffer (if at all) and when the caller provides us with the contents of a
commit.

Verify that the commit we are being asked to create references objects which do
exist in the target repository.

This is not terribly efficient since we allocate a commit, but AFAICT it's what we have available. Obviously our test suite fails with these changes because we were creating commits that referenced non-existent trees and commits.

Fixes #5288

…nature

There can be a significant difference between the system where we created the
buffer (if at all) and when the caller provides us with the contents of a
commit.

Provide some test cases (we have to adapt the existing ones because they refer
to trees and commits which do not exist).
There can be a significant difference between the system where we created the
buffer (if at all) and when the caller provides us with the contents of a
commit.

Verify that the commit we are being asked to create references objects which do
exist in the target repository.
Comment thread src/commit.c
goto cleanup;

if ((error = validate_tree_and_parents(&parents, repo, &parsed->tree_id, commit_parent_from_commit, parsed, NULL, true)) < 0)
goto cleanup;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it certain that parents doesn't have to be cleared if validate_tree_and_parents returns an error?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it to me - the error case of validate_tree_and_parents fn will clear the parents array before returning, if it had ever allocated anything into it.

@ethomson
Copy link
Copy Markdown
Member

ethomson commented Nov 1, 2019

LGTM. Thanks, @carlosmn, for finding and fixing strange ordering bugs!

@ethomson ethomson merged commit d5017a1 into master Nov 1, 2019
@ethomson
Copy link
Copy Markdown
Member

ethomson commented Nov 1, 2019

It looks like the existing verify function doesn't honor GIT_OPT_ENABLE_STRICT_OBJECT_CREATION? Or am I missing something?

This limitation doesn't hold this up, since it's an important fix. But I wanted to ask.

@carlosmn
Copy link
Copy Markdown
Member Author

carlosmn commented Nov 1, 2019

It looks like the existing verify function doesn't honor GIT_OPT_ENABLE_STRICT_OBJECT_CREATION? Or am I missing something?

Do you mean validate_tree_and_parents? The GIT_OPT_ENABLE_STRICT_OBJECT_CREATION option, aka git_object__strict_input_validation is checked within git_object__is_valid so even though we're passing true for validate it's still down to the setting whether we actually perform the check.

@carlosmn carlosmn deleted the cmn/create-with-signature-verification branch November 1, 2019 12:18
@ethomson
Copy link
Copy Markdown
Member

ethomson commented Nov 1, 2019

Do you mean validate_tree_and_parents? The GIT_OPT_ENABLE_STRICT_OBJECT_CREATION option, aka git_object__strict_input_validation is checked within git_object__is_valid so even though we're passing true for validate it's still down to the setting whether we actually perform the check.

Yes, somehow I forgot how variables work and boolean logic. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git_commit_create_with_signature does not check the tree exists

3 participants