diff options
author | Erdur <Erdur@gmx.at> | 2014-09-30 16:19:24 +0200 |
---|---|---|
committer | Carlos MartÃn Nieto <cmn@dwim.me> | 2014-09-30 16:19:24 +0200 |
commit | 44802c551e83c4c80295d6d246b933f5efa39041 (patch) | |
tree | a9ba13c2fe71b619cb00fe5c6609fa4c7d449e14 | |
parent | a2a23322193eeca5d2912c0b74c5374f8ec21737 (diff) | |
download | libgit2-44802c551e83c4c80295d6d246b933f5efa39041.tar.gz |
path: fix invalid access
-rw-r--r-- | src/path.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/path.c b/src/path.c index 67133f97e..21b6e18d6 100644 --- a/src/path.c +++ b/src/path.c @@ -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); |