{"thread":{"id":"43297","subject":"\"git fmt-merge-msg\" SIGSEGV","startedAt":"2006-11-17T06:57:20Z","lastAt":"2006-11-17T06:57:20Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"294259","messageId":"Pine.LNX.4.64.0611162249540.3349@woody.osdl.org","threadId":"43297","inReplyTo":null,"subject":"\"git fmt-merge-msg\" SIGSEGV","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-11-17T06:57:20Z","receivedAt":"2006-11-17T06:57:20Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nOk, this is a _really_ stupid case, and I don't think it matters, but hey, \nwe should never SIGSEGV.\n\nSteps to reproduce:\n\n\tmkdir duh\n\tcd duh\n\tgit init-db\n\tgit-fmt-merge-msg < /dev/null\n\nwill cause a SIGSEGV in cmd_fmt_merge_msg(), because we're doing a \nstrncmp() with a NULL current_branch.\n\nAnd yeah, it's an insane schenario, and no, it doesn't really matter. The \nonly reason I noticed was that a broken version of my \"git pull\" into an \nempty directory would cause this.\n\nThis silly patch just replaces the SIGSEGV with a controlled exit with an \nerror message.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex 3d3097d..87d3d63 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -278,6 +278,8 @@ int cmd_fmt_merge_msg(int argc, const ch\n \n \t/* get current branch */\n \tcurrent_branch = resolve_ref(\"HEAD\", head_sha1, 1, NULL);\n+\tif (!current_branch)\n+\t\tdie(\"No current branch\");\n \tif (!strncmp(current_branch, \"refs/heads/\", 11))\n \t\tcurrent_branch += 11;\n"}]}