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

"git fmt-merge-msg" SIGSEGV

From
Linus Torvalds <torvalds@osdl.org>
Date
Nov 17, 2006, 06:57 UTC
Message-ID
<Pine.LNX.4.64.0611162249540.3349@woody.osdl.org>

Ok, this is a _really_ stupid case, and I don't think it matters, but hey, we should never SIGSEGV.

Steps to reproduce:
	mkdir duh
	cd duh
	git init-db
	git-fmt-merge-msg < /dev/null

will cause a SIGSEGV in cmd_fmt_merge_msg(), because we're doing a strncmp() with a NULL current_branch.

And yeah, it's an insane schenario, and no, it doesn't really matter. The only reason I noticed was that a broken version of my "git pull" into an empty directory would cause this.

This silly patch just replaces the SIGSEGV with a controlled exit with an error message.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c
index 3d3097d..87d3d63 100644
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
@@ -278,6 +278,8 @@ int cmd_fmt_merge_msg(int argc, const ch
 
 	/* get current branch */
 	current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
+	if (!current_branch)
+		die("No current branch");
 	if (!strncmp(current_branch, "refs/heads/", 11))
 		current_branch += 11;
Message 1 of 1 in “"git fmt-merge-msg" SIGSEGV”
  1. Linus TorvaldsNov 17, 2006

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.