Commit 6d24f9a
committed
worktree: don't read out of bounds
`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>1 parent 9a0c470 commit 6d24f9a
1 file changed
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
311 | 315 | | |
312 | 316 | | |
313 | 317 | | |
| |||
0 commit comments