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

Re: git stash apply segfaulting when called in subdir

From
Jeff King <peff@peff.net>
Date
Jul 26, 2007, 05:07 UTC
Message-ID
<20070726050726.GC32617@coredump.intra.peff.net>
In-Reply-To
<7v1wewdsoz.fsf@assigned-by-dhcp.cox.net>
On Wed, Jul 25, 2007 at 03:28:12PM -0700, Junio C Hamano wrote:
Show 6 quoted lines
> > zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
> > error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
> > /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree
> 
> This probably is a merge-recursive bug, but in the meantime,
> I think this should fix it.

The merge-recursive bug is simply a failure to check for invalid input. Patch to at least print and die rather than segfault is below. Technically the error could be from a tag dereference, too, so maybe the error message should be more exact?

-- >8 -- merge-recursive: don't segfault on missing input objects

This should generally never happen, but it's nicer to report an error than to segfault.

Signed-off-by: Jeff King <peff@peff.net>
---
 merge-recursive.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index c8539ec..2764e61 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1692,6 +1692,8 @@ static struct commit *get_ref(const char *ref)
 	if (get_sha1(ref, sha1))
 		die("Could not resolve ref '%s'", ref);
 	object = deref_tag(parse_object(sha1), ref, strlen(ref));
+	if (!object)
+		die("Object does not exist: %s", ref);
 	if (object->type == OBJ_TREE)
 		return make_virtual_commit((struct tree*)object,
 			better_branch_name(ref));
-- 
1.5.3.rc3.818.gc1dc7-dirty
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 4 of 7 in “git stash apply segfaulting when called in subdir”
  1. Uwe Kleine-KönigJul 25, 2007
  2. Junio C HamanoJul 25, 2007
  3. Johannes SchindelinJul 25, 2007
  4. Jeff KingJul 26, 2007
  5. Johannes SchindelinJul 26, 2007
  6. Jeff KingJul 26, 2007
  7. Steven WalterJul 25, 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.