Re: [PATCH] read-cache: make `do_read_index()` always set up `istate->repo`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Ågren <martin.agren@xxxxxxxxx> writes:

> If there is no index file, e.g., because the repository has just been
> created, we return zero early (unless `must_exist` makes us die
> instead.)
>
> This early return means we do not set up `istate->repo`. With
> `core.untrackedCache=true`, the recent e6a653554b ("untracked-cache:
> support '--untracked-files=all' if configured", 2022-03-31) will
> eventually pass down `istate->repo` as a null pointer to
> `repo_config_get_string()`, causing a segmentation fault.
>
> If we do hit this early return, set up `istate->repo` similar to when we
> actually read the index.
>
> Reported-by: Joey Hess <id@xxxxxxxxxx>
> Signed-off-by: Martin Ågren <martin.agren@xxxxxxxxx>
> ---
>  read-cache.c                      | 5 ++++-
>  t/t7063-status-untracked-cache.sh | 6 ++++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 3e0e7d4183..68ed65035b 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2268,8 +2268,11 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
>  	istate->timestamp.nsec = 0;
>  	fd = open(path, O_RDONLY);
>  	if (fd < 0) {
> -		if (!must_exist && errno == ENOENT)
> +		if (!must_exist && errno == ENOENT) {
> +			if (!istate->repo)
> +				istate->repo = the_repository;
>  			return 0;
> +		}

Makes sense.

>  		die_errno(_("%s: index file open failed"), path);
>  	}
>  
> diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
> index 9936cc329e..7dc5631f3d 100755
> --- a/t/t7063-status-untracked-cache.sh
> +++ b/t/t7063-status-untracked-cache.sh
> @@ -985,4 +985,10 @@ test_expect_success '"status" after file replacement should be clean with UC=fal
>  	status_is_clean
>  '
>  
> +test_expect_success 'empty repo (no index) and core.untrackedCache' '
> +	git init emptyrepo &&
> +	cd emptyrepo/ &&
> +	git -c core.untrackedCache=true write-tree
> +'

I'll tweak this with "-C emptyrepo" so that future developers do not
have to get bitten when they add more tests to this script.

THanks for a quick fix.  Very much appreciated.

>  test_done




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux