Commit 04f78802 by Brodie Rao

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:

https://github.com/jquery/jquery/commit/25b424134f9927a5bf0bab5cba836a0aa6c3cfc1
parent 3eaf34f4
......@@ -221,10 +221,10 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
}
/* parse commit message */
while (buffer < buffer_end && *buffer == '\n')
while (buffer < buffer_end - 1 && *buffer == '\n')
buffer++;
if (buffer < buffer_end) {
if (buffer <= buffer_end) {
commit->message = git__strndup(buffer, buffer_end - buffer);
if (!commit->message)
return GIT_ENOMEM;
......
be3563ae3f795b2b4353bcce3a527ad0a4f7f644
a65fedf39aefe402d3bb6e24df4d4f5fe4547750
......@@ -560,6 +560,7 @@ static const char *commit_ids[] = {
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", /* 6 */
};
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(committer->name, "Scott Chacon") == 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(commit_time > 0);
must_be_true(parents <= 2);
......
......@@ -70,7 +70,7 @@ END_TEST
static const char *head_tracker_sym_ref_name = "head-tracker";
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")
git_repository *repo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment