Skip to content

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

@florianpircher

Description

@florianpircher

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions