Commit 04f788023fd04e60a12c2a19787857c72b3817f4

Brodie Rao 2011-08-09T20:49:12

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

diff --git a/src/commit.c b/src/commit.c
index 0ee3854..ced457e 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -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;
diff --git a/tests/resources/testrepo.git/objects/36/97d64be941a53d4ae8f6a271e4e3fa56b022cc b/tests/resources/testrepo.git/objects/36/97d64be941a53d4ae8f6a271e4e3fa56b022cc
new file mode 100644
index 0000000..9bb5b62
Binary files /dev/null and b/tests/resources/testrepo.git/objects/36/97d64be941a53d4ae8f6a271e4e3fa56b022cc differ
diff --git a/tests/resources/testrepo.git/objects/94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162 b/tests/resources/testrepo.git/objects/94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162
new file mode 100644
index 0000000..4cc3f4d
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162
@@ -0,0 +1 @@
+x+)JMU044b040031QrutueXlmmAṃJ}G;UTWRQ`6Kǥ^/-*|W3Py`%E\&g|0{Ӎ1X
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe4547750 b/tests/resources/testrepo.git/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe4547750
new file mode 100644
index 0000000..29c8e82
--- /dev/null
+++ b/tests/resources/testrepo.git/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe4547750
@@ -0,0 +1,3 @@
+xQ
+!@sBQ"	ٱ
r{<xƪ
+HlJSer!ZPTe*jUEo^2(XS€EDO<Yj$2s_&},}[~p7~<:	Zp?1_C0
\ No newline at end of file
diff --git a/tests/resources/testrepo.git/refs/heads/master b/tests/resources/testrepo.git/refs/heads/master
index 9536ad8..3d8f0a4 100644
--- a/tests/resources/testrepo.git/refs/heads/master
+++ b/tests/resources/testrepo.git/refs/heads/master
@@ -1 +1 @@
-be3563ae3f795b2b4353bcce3a527ad0a4f7f644
+a65fedf39aefe402d3bb6e24df4d4f5fe4547750
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index 88c7efd..58d24bf 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -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);
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 6703415..1b3e0a3 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -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;