All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: "Matthias Aßhauer via GitGitGadget" <gitgitgadget@gmail.com>,
	git@vger.kernel.org, "Marc Branchaud" <marcnarc@xiplink.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Matthias Aßhauer" <mha1993@live.de>
Subject: Re: [PATCH v1.5] worktree: Fix out of bounds read that causes data loss and reject invalid empty input in worktree add
Date: Tue, 11 Aug 2026 15:46:05 -0700	[thread overview]
Message-ID: <xmqqwltwz36a.fsf@gitster.g> (raw)
In-Reply-To: <52ee6501-24ac-402b-b650-92a829030380@web.de> ("René Scharfe"'s message of "Tue, 11 Aug 2026 23:34:07 +0200")

René Scharfe <l.s.r@web.de> writes:

> From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>
>
> `worktree_basename` tries to read from memory before the passed `path`
> string, if `path` is empty (or only consists of directory separators).
> That results in unexpected nonsense data being returned to the caller,
> which can lead to issues, such as `git worktree add ""` recursively
> deleting the current working directory, including `.git`.
>
> Stop reading out of bounds in these cases to avoid that behaviour.
>
> This leads to `git worktree add ""` consistently exiting with the
> message `BUG: How come '' becomes empty after sanitization?`, which is
> still undesirable, but at least it doesn't result in data loss anymore.
>
> This fixes https://github.com/git-for-windows/git/issues/6346
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> How about this while we're waiting for a reroll?  It implements what the
> commit message says, nothing more.  Follows the style of the first loop.

This one I think is obvious and clear.  Why not take the authorship
too so that we do not have to worry about DCO?

>
>  builtin/worktree.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index 654d27c3e1..a770dd5ead 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -303,11 +303,9 @@ static const char *worktree_basename(const char *path, int *olen)
>  	while (len && is_dir_sep(path[len - 1]))
>  		len--;
>  
> -	for (name = path + len - 1; name > path; name--)
> -		if (is_dir_sep(*name)) {
> -			name++;
> -			break;
> -		}
> +	name = path + len;
> +	while (name > path && !is_dir_sep(name[-1]))
> +		name--;
>  
>  	*olen = len;
>  	return name;

      reply	other threads:[~2026-08-11 22:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 11:19 [PATCH 0/2] worktree: Fix out of bounds read that causes data loss and reject invalid empty input in worktree add Matthias Aßhauer via GitGitGadget
2026-07-25 11:19 ` [PATCH 1/2] worktree: don't read out of bounds Matthias Aßhauer via GitGitGadget
2026-07-25 16:51   ` Junio C Hamano
2026-07-31  5:45     ` René Scharfe
2026-07-25 11:19 ` [PATCH 2/2] worktree: reject empty string Matthias Aßhauer via GitGitGadget
2026-08-02  6:26   ` René Scharfe
2026-08-02  9:58     ` René Scharfe
2026-08-11 21:34 ` [PATCH v1.5] worktree: Fix out of bounds read that causes data loss and reject invalid empty input in worktree add René Scharfe
2026-08-11 22:46   ` Junio C Hamano [this message]

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

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

  git send-email \
    --in-reply-to=xmqqwltwz36a.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=l.s.r@web.de \
    --cc=marcnarc@xiplink.com \
    --cc=mha1993@live.de \
    --cc=pclouds@gmail.com \
    --cc=sunshine@sunshineco.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.