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

[PATCH] branch: fix segfault when resolving an invalid HEAD

From
Jonas Fonseca <fonseca@diku.dk>
Date
May 20, 2007, 12:19 UTC
Message-ID
<20070520121917.GA18850@diku.dk>

Caused by return value of resolve_ref being passed directly to xstrdup whereby the sanity checking was never reached.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 builtin-branch.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
 Discovered while renaming a ref from "a/b" to "a" while redoing some
 changes. After a `git push --all`, `git branch` in the remote repo
 segfaulted, since its HEAD was still pointing to "a/b".
diff --git a/builtin-branch.c b/builtin-branch.c
index 6bd5843..a5b6bbe 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -623,9 +623,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	    (rename && force_create))
 		usage(builtin_branch_usage);
 
-	head = xstrdup(resolve_ref("HEAD", head_sha1, 0, NULL));
+	head = resolve_ref("HEAD", head_sha1, 0, NULL);
 	if (!head)
 		die("Failed to resolve HEAD as a valid ref.");
+	head = xstrdup(head);
 	if (!strcmp(head, "HEAD")) {
 		detached = 1;
 	}
-- 
1.5.2.rc3.800.ga489e-dirty

-- 
Jonas Fonseca
Next: Jonas Fonseca
Message 1 of 2 in “branch: fix segfault when resolving an invalid HEAD”
  1. branch: fix segfault when resolving an invalid HEADJonas Fonseca, May 20, 2007
  2. Jonas FonsecaMay 20, 2007

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.