git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Martin Ågren" <martin.agren@gmail.com>
To: Joey Hess <id@joeyh.name>
Cc: git@vger.kernel.org, Tao Klerks <tao@klerks.biz>
Subject: Re: git write-tree segfault with core.untrackedCache true and nonexistent index
Date: Fri, 22 Jul 2022 21:25:59 +0200	[thread overview]
Message-ID: <20220722192559.718264-1-martin.agren@gmail.com> (raw)
In-Reply-To: <YtrdPguYs3a3xekv@kitenet.net>

On Fri, 22 Jul 2022 at 20:20, Joey Hess <id@joeyh.name> wrote:
>
>         joey@darkstar:/tmp>git init emptyrepo
>         Initialized empty Git repository in /tmp/emptyrepo/.git/
>         joey@darkstar:/tmp>cd emptyrepo/
>         joey@darkstar:/tmp/emptyrepo>git config core.untrackedCache true
>         joey@darkstar:/tmp/emptyrepo>git write-tree
>         Segmentation fault
>
[...]
>
> Bisecting, e6a653554bb49c26d105f3b478cbdbb1c0648f65 is the first bad commit
> commit e6a653554bb49c26d105f3b478cbdbb1c0648f65
> Author: Tao Klerks <tao@klerks.biz>
> Date:   Thu Mar 31 16:02:15 2022 +0000
>
>     untracked-cache: support '--untracked-files=all' if configured

Thanks for a clear description, and for bisecting.

`repo` is NULL in `new_untracked_cache_flags()` and we're not prepared
for that. The diff below fixes this in the sense that your reproducer
stops failing, but I'm not sure it's the best approach.

I can't help but think that e6a653554b was just unlucky enough to
dereference `istate->repo` and that the real issue is that we're missing

	if (!istate->repo)
		istate->repo = the_repository;

in some strategic place a fair bit earlier. It seems to me like the diff
below is just papering over the real bug. It's not obvious to me where
that check would want to go, though. Tao, do you have an idea?

Martin

--- a/dir.c
+++ b/dir.c
@@ -2752,6 +2752,9 @@ static unsigned new_untracked_cache_flags(struct index_state *istate)
 	struct repository *repo = istate->repo;
 	char *val;
 
+	if (!repo)
+		repo = the_repository;
+
 	/*
 	 * This logic is coordinated with the setting of these flags in
 	 * wt-status.c#wt_status_collect_untracked(), and the evaluation
-- 
2.37.1.455.g008518b4e5


  reply	other threads:[~2022-07-22 19:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 17:24 git write-tree segfault with core.untrackedCache true and nonexistent index Joey Hess
2022-07-22 19:25 ` Martin Ågren [this message]
2022-07-22 19:41   ` Junio C Hamano
2022-07-22 21:22     ` [PATCH] read-cache: make `do_read_index()` always set up `istate->repo` Martin Ågren
2022-07-22 21:46       ` Junio C Hamano
2022-07-22 22:00         ` Martin Ågren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220722192559.718264-1-martin.agren@gmail.com \
    --to=martin.agren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=id@joeyh.name \
    --cc=tao@klerks.biz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).