aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolashillegeer@gmail.com>2017-04-07 12:29:17 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-04-07 12:29:17 +0200
commit1813076c448f1039db33e08e83b7f1f2011db0ee (patch)
tree952d791112403c35dddb3370b8d0ab69ee7fc2b7
parent30e1cda8acb7bd8120348d1812cfd9ecd8be8528 (diff)
downloadrneovim-1813076c448f1039db33e08e83b7f1f2011db0ee.tar.gz
rneovim-1813076c448f1039db33e08e83b7f1f2011db0ee.tar.bz2
rneovim-1813076c448f1039db33e08e83b7f1f2011db0ee.zip
eval: delimit string with NUL byte (#6467)
A recent refactor left cpy without a NUL terminator, simplify the code instead of patching over it. Instead of plain memcpy, it'd be better to employ harder to misuse string functions made for this purpose like xstrlcpy(), but path_tail() takes char_u arguments and returns them, leading to a lot of ugly casting. Fixes #6431.
-rw-r--r--src/nvim/eval.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 7ab07fe6a2..1636b490d5 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -13416,14 +13416,12 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr)
q = (char *)path_tail((char_u *)p);
}
if (q > p && !path_is_absolute_path((const char_u *)buf)) {
- // Symlink is relative to directory of argument.
+ // Symlink is relative to directory of argument. Replace the
+ // symlink with the resolved name in the same directory.
const size_t p_len = strlen(p);
const size_t buf_len = strlen(buf);
- cpy = xmalloc(p_len + buf_len + 1);
- memcpy(cpy, p, p_len);
- memcpy(path_tail((char_u *)cpy), buf, buf_len + 1);
- xfree(p);
- p = cpy;
+ p = xrealloc(p, p_len + buf_len + 1);
+ memcpy(path_tail((char_u *)p), buf, buf_len + 1);
} else {
xfree(p);
p = xstrdup(buf);