worktree: Fix out of bounds read that causes data loss and reject invalid empty input in worktree add#2187
Open
rimrul wants to merge 2 commits into
Open
worktree: Fix out of bounds read that causes data loss and reject invalid empty input in worktree add#2187rimrul wants to merge 2 commits into
rimrul wants to merge 2 commits into
Conversation
|
There is an issue in commit 6d24f9a:
|
|
There is an issue in commit 500ec11:
|
`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 git-for-windows#6346 Signed-off-by: Matthias Aßhauer <mha1993@live.de>
`git worktree add ""` errors out with the message `BUG: How come '' becomes empty after sanitization?`, but not due to a bug in the sanitization code. An empty string should remain empty during sanitization. Instead reject the argument as invalid user input, if it's already empty before sanitization. Signed-off-by: Matthias Aßhauer <mha1993@live.de>
Author
|
/submit |
|
Submitted as pull.2187.git.1784978348.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Passing an empty string to
git worktree add(typically via an unset variable, e.g.git worktree add "$UNSET_VAR" -b tb origin/main) can result inBUG: How come '' becomes empty after sanitization?but it can also have worse consequences: recursively deleting the current working directory, including.git. The inconsistent behaviour is caused byworktree_basenamereading unrelated bytes from the memory beforepathand passing that back toadd_worktree, which can circumvent the check for theBUGcall.CC: Marc Branchaud marcnarc@xiplink.com
CC: Nguyễn Thái Ngọc Duy pclouds@gmail.com
CC: Eric Sunshine sunshine@sunshineco.com