mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
fix(path): check return value of append_path() (#28309)
If the filename passed to vim_FullName() is a relative directory, and does not exist, it is appended to the current working directory. Since the return value of append_path() was ignored, and if the buffer length was too small to fit getcwd() + dirname(filename), it would still try to append the basename(filename). This was manifesting as a failure in test/unit/path_spec.lua in: itp('fails and uses filename if given filename contains non-existing directory', .. This failure occurs when running the tests from directory with a short path such as: /work/src/nv test/unit/path_spec.lua:420: Expected objects to be the same. Passed in: (string) '/work/src/nv/test.file' Expected: (string) 'non_existing_dir/test.file' This return value for the second call to append_path() to append basename(filename) was checked, and this is where it would fail for normal / longer getcwd()s.
This commit is contained in:
parent
780509aedf
commit
f064e72b9b
@ -375,7 +375,7 @@ static bool is_executable_in_path(const char *name, char **abspath)
|
|||||||
|
|
||||||
// Combine the $PATH segment with `name`.
|
// Combine the $PATH segment with `name`.
|
||||||
xstrlcpy(buf, p, (size_t)(e - p) + 1);
|
xstrlcpy(buf, p, (size_t)(e - p) + 1);
|
||||||
append_path(buf, name, buf_len);
|
(void)append_path(buf, name, buf_len);
|
||||||
|
|
||||||
#ifdef MSWIN
|
#ifdef MSWIN
|
||||||
if (is_executable_ext(buf, abspath)) {
|
if (is_executable_ext(buf, abspath)) {
|
||||||
|
@ -2301,7 +2301,9 @@ int path_full_dir_name(char *directory, char *buffer, size_t len)
|
|||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
} else {
|
} else {
|
||||||
xstrlcpy(buffer, old_dir, len);
|
xstrlcpy(buffer, old_dir, len);
|
||||||
append_path(buffer, directory, len);
|
if (append_path(buffer, directory, len) == FAIL) {
|
||||||
|
retval = FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (os_dirname(buffer, len) == FAIL) {
|
} else if (os_dirname(buffer, len) == FAIL) {
|
||||||
// Do not return immediately since we are in the wrong directory.
|
// Do not return immediately since we are in the wrong directory.
|
||||||
|
@ -413,12 +413,15 @@ describe('path.c', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
itp('fails and uses filename if given filename contains non-existing directory', function()
|
itp('fails and uses filename if given filename contains non-existing directory', function()
|
||||||
local filename = 'non_existing_dir/test.file'
|
-- test with different filename lengths
|
||||||
local buflen = string.len(filename) + 1
|
for rep = 1, 10 do
|
||||||
local do_expand = 1
|
local filename = ('non_existing_'):rep(rep) .. 'dir/test.file'
|
||||||
local buf, result = vim_FullName(filename, buflen, do_expand)
|
local buflen = string.len(filename) + 1
|
||||||
eq(filename, ffi.string(buf))
|
local do_expand = 1
|
||||||
eq(FAIL, result)
|
local buf, result = vim_FullName(filename, buflen, do_expand)
|
||||||
|
eq(filename, ffi.string(buf))
|
||||||
|
eq(FAIL, result)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
itp('concatenates filename if it does not contain a slash', function()
|
itp('concatenates filename if it does not contain a slash', function()
|
||||||
|
Loading…
Reference in New Issue
Block a user