8000 1.8.0: Calling git_commit_create_from_stage without author and committer does not use the default committer · Issue #6777 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

1.8.0: Calling git_commit_create_from_stage without author and committer does not use the default committer #6777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
florianpircher opened this issue Mar 21, 2024 · 2 comments

Comments

@florianpircher
Copy link
Contributor
florianpircher commented Mar 21, 2024

Reproduction steps

Call git_commit_create_from_stage with either

  • given_opts of NULL or
  • given_opts with both author and committer of NULL.

Expected behavior

The default author and committer are used, as per

/** The commit author, or NULL for the default. */
const git_signature *author;
/** The committer, or NULL for the default. */
const git_signature *committer;

Actual behavior

The default committer is not used, leaving the internal committer variable of git_commit_create_from_stage uninitialized, leading to EXC_BAD_ACCESS or similar issues.

Version of libgit2 (release number or SHA1)

d74d491 (1.8.0)

Operating system(s) tested

macOS 14.2.1 (23C71)

Debugging

The variables are set up here:

libgit2/src/libgit2/commit.c

Lines 1089 to 1097 in d74d491

int git_commit_create_from_stage(
git_oid *out,
git_repository *repo,
const char *message,
const git_commit_create_options *given_opts)
{
git_commit_create_options opts = GIT_COMMIT_CREATE_OPTIONS_INIT;
git_signature *default_signature = NULL;
const git_signature *author, *committer;

and checked here:

libgit2/src/libgit2/commit.c

Lines 1110 to 1120 in d74d491

if ((author = opts.author) == NULL ||
(committer = opts.committer) == NULL) {
if (git_signature_default(&default_signature, repo) < 0)
goto done;
if (!author)
author = default_signature;
if (!committer)
committer = default_signature;
}

However, if (author = opts.author) == NULL, the condition short-circuits and committer = opts.committer is never run, leaving committer uninitialized. The code

libgit2/src/libgit2/commit.c

Lines 1118 to 1119 in d74d491

if (!committer)
committer = default_signature;

will thus most likely not be executed, meaning the default committer is never set and instead the uninitialized committer is used in the following code.


Thanks for the addition of git_commit_create_from_stage, this is a handy shortcut!

@Uncommon
Copy link
Contributor

I just now ran into this and was about to file an issue. Good thing I checked first :)

@ethomson
Copy link
Member

Oops - thanks for the report.

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

No branches or pull requests

3 participants
0