mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-21 22:21:37 +00:00
commit: properly parse empty commit messages
This ensures commit->message is always non-NULL, even if the commit
message is empty or consists of only a newline.
One such commit can be found in the wild in the jQuery repository:
25b424134f
This commit is contained in:
parent
3eaf34f4c6
commit
04f788023f
@ -221,10 +221,10 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* parse commit message */
|
/* parse commit message */
|
||||||
while (buffer < buffer_end && *buffer == '\n')
|
while (buffer < buffer_end - 1 && *buffer == '\n')
|
||||||
buffer++;
|
buffer++;
|
||||||
|
|
||||||
if (buffer < buffer_end) {
|
if (buffer <= buffer_end) {
|
||||||
commit->message = git__strndup(buffer, buffer_end - buffer);
|
commit->message = git__strndup(buffer, buffer_end - buffer);
|
||||||
if (!commit->message)
|
if (!commit->message)
|
||||||
return GIT_ENOMEM;
|
return GIT_ENOMEM;
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -560,6 +560,7 @@ static const char *commit_ids[] = {
|
|||||||
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
|
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
|
||||||
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
|
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
|
||||||
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
|
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
|
||||||
|
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", /* 6 */
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_TEST(details0, "query the details on a parsed commit")
|
BEGIN_TEST(details0, "query the details on a parsed commit")
|
||||||
@ -594,6 +595,7 @@ BEGIN_TEST(details0, "query the details on a parsed commit")
|
|||||||
must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
|
must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
|
||||||
must_be_true(strcmp(committer->name, "Scott Chacon") == 0);
|
must_be_true(strcmp(committer->name, "Scott Chacon") == 0);
|
||||||
must_be_true(strcmp(committer->email, "schacon@gmail.com") == 0);
|
must_be_true(strcmp(committer->email, "schacon@gmail.com") == 0);
|
||||||
|
must_be_true(message != NULL);
|
||||||
must_be_true(strchr(message, '\n') != NULL);
|
must_be_true(strchr(message, '\n') != NULL);
|
||||||
must_be_true(commit_time > 0);
|
must_be_true(commit_time > 0);
|
||||||
must_be_true(parents <= 2);
|
must_be_true(parents <= 2);
|
||||||
|
@ -70,7 +70,7 @@ END_TEST
|
|||||||
|
|
||||||
static const char *head_tracker_sym_ref_name = "head-tracker";
|
static const char *head_tracker_sym_ref_name = "head-tracker";
|
||||||
static const char *current_head_target = "refs/heads/master";
|
static const char *current_head_target = "refs/heads/master";
|
||||||
static const char *current_master_tip = "be3563ae3f795b2b4353bcce3a527ad0a4f7f644";
|
static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
|
||||||
|
|
||||||
BEGIN_TEST(readsym0, "lookup a symbolic reference")
|
BEGIN_TEST(readsym0, "lookup a symbolic reference")
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
|
Loading…
Reference in New Issue
Block a user