worktree add: don't read out of bounds in worktree_basename()
When we search for the start of the basename and `len` is zero, `name` ends up being `path` - 1, out of bounds. Avoid that by checking before decrementing. Fixes https://github.com/git-for-windows/git/issues/6346. Original-patch-by: Matthias Aßhauer <mha1993@live.de> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>jch
parent
e9019fcafe
commit
997c1daf1d
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue