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

Re: [bug] Segfault in git commit when a hook has a broken shebang

From
Đoàn Trần Công Danh <congdanhqx@gmail.com>
Date
Aug 5, 2022, 07:52 UTC
Message-ID
<YuzML2lVGDBIK1uF@danh.dev>
In-Reply-To
<30015309-00f1-9b44-023c-001ee3f242e4@0upti.me>
On 2022-08-05 08:45:02+0300, Ilya K <me@0upti.me> wrote:
Show 13 quoted lines
> Hello! I ran into a weird bug just now that is probably easier to show than
> explain:
> ❯ git init
> Initialized empty Git repository in /home/k900/test/.git/
> ❯ echo '#!/usr/bin/oops' > .git/hooks/pre-commit
> ❯ chmod +x .git/hooks/pre-commit
> ❯ touch oops
> ❯ git add oops
> ❯ git commit -a
> fatal: cannot run .git/hooks/pre-commit: No such file or directory
> [1]    24580 segmentation fault (core dumped)  git commit -a
> This happens consistently with git 2.37.x, and I don't think it happened
> with git 2.36 or earlier.

This seems to be a side-effect of a082345372, (hook API: fix v2.36.0 regression: hooks should be connected to a TTY, 2022-06-07)

Since it makes hooks run in "ungroup" manner, hence run-command will pass NULL as first argument to notify_start_failure.

This patch seems to fix the crash, however, I think we should remove that clause entirely.

---- 8< -------
 hook.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hook.c b/hook.c
index d113ee7faa..dc54a2ac67 100644
--- a/hook.c
+++ b/hook.c
@@ -84,8 +84,8 @@ static int notify_start_failure(struct strbuf *out,
 
 	hook_cb->rc |= 1;
 
-	strbuf_addf(out, _("Couldn't start hook '%s'\n"),
-		    hook_path);
+	fprintf(stderr, _("Couldn't start hook '%s'\n"),
+		hook_path);
 
 	return 1;
 }
----- >8 --------------
-- 
Danh
Previous: Ilya KNext: Ævar Arnfjörð Bjarmason
Message 2 of 5 in “[bug] Segfault in git commit when a hook has a broken shebang”
  1. Ilya KAug 5, 2022
  2. Đoàn Trần Công DanhAug 5, 2022
  3. Ævar Arnfjörð BjarmasonAug 5, 2022
  4. Ævar Arnfjörð BjarmasonAug 5, 2022
  5. Emily ShafferAug 5, 2022

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.