-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Reproduction steps
Call git_commit_create_from_stage
with either
given_opts
ofNULL
orgiven_opts
with bothauthor
andcommitter
ofNULL
.
Expected behavior
The default author and committer are used, as per
Lines 409 to 413 in d74d491
/** 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:
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:
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
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!