git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 2a] pretty: detect missing \n\n in commit message

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 28, 2012, 10:37 UTC
Message-ID
<5234ba4babd28d9430750d227d629b4d4386b131.1330425111.git.trast@student.ethz.ch>
In-Reply-To
<010901fbfffe0f806bb19d556ebc1e512a4697f4.1330425111.git.trast@student.ethz.ch>

get_header()'s exit condition is finding the \n\n that separates the commit header from its message. If such a double newline is not present, it segfaults. Catch this case and die().

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

This would be the minimal fix to the pretty machinery so that 'git rev-list --pretty=something HEAD' works when there are such broken commits.

If 2b goes in, there isn't really any point as we would never get this far on such a commit.

 pretty.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/pretty.c b/pretty.c
index 8688b8f..b7f097d 100644
--- a/pretty.c
+++ b/pretty.c
@@ -440,7 +440,10 @@ static char *get_header(const struct commit *commit, const char *key)
 	const char *line = commit->buffer;
 
 	for (;;) {
-		const char *eol = strchr(line, '\n'), *next;
+		const char *eol, *next;
+		if (!line)
+			die (_("malformed commit object: no separating \\n\\n?"));
+		eol = strchr(line, '\n');
 
 		if (line == eol)
 			return NULL;
-- 
1.7.9.2.467.g7fee4
Previous: Thomas RastNext: Nguyen Thai Ngoc Duy
Message 9 of 13 in “commit: allow {--amend|-c foo} when {HEAD|foo} has empty message”
  1. commit: allow {--amend|-c foo} when {HEAD|foo} has empty messageThomas Rast, Feb 28, 2012
  2. Jeff KingFeb 28, 2012
  3. Jeff KingFeb 28, 2012
  4. Thomas RastFeb 28, 2012
  5. Junio C HamanoFeb 28, 2012
  6. Jeff KingFeb 28, 2012
  7. Junio C HamanoFeb 28, 2012
  8. commit: allow {--amend|-c foo} when {HEAD|foo} has empty messageThomas Rast, Feb 28, 2012
  9. pretty: detect missing \n\n in commit messageThomas Rast, Feb 28, 2012
  10. Nguyen Thai Ngoc DuyFeb 28, 2012
  11. Junio C HamanoFeb 28, 2012
  12. parse_commit: refuse to load commit without \n\n separatorThomas Rast, Feb 28, 2012
  13. Junio C HamanoFeb 28, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.