mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-11 15:37:23 +00:00
path: fix invalid access
This commit is contained in:
parent
a2a2332219
commit
44802c551e
@ -768,7 +768,7 @@ int git_path_cmp(
|
||||
int git_path_make_relative(git_buf *path, const char *parent)
|
||||
{
|
||||
const char *p, *q, *p_dirsep, *q_dirsep;
|
||||
size_t plen = path->size, newlen, depth = 1, i;
|
||||
size_t plen = path->size, newlen, depth = 1, i, offset;
|
||||
|
||||
for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) {
|
||||
if (*p == '/' && *q == '/') {
|
||||
@ -808,8 +808,11 @@ int git_path_make_relative(git_buf *path, const char *parent)
|
||||
|
||||
newlen = (depth * 3) + plen;
|
||||
|
||||
/* save the offset as we might realllocate the pointer */
|
||||
offset = p - path->ptr;
|
||||
if (git_buf_try_grow(path, newlen + 1, 1, 0) < 0)
|
||||
return -1;
|
||||
p = path->ptr + offset;
|
||||
|
||||
memmove(path->ptr + (depth * 3), p, plen + 1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user