aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2019-07-04 21:45:51 +0900
committerJustin M. Keyes <justinkz@gmail.com>2019-07-04 14:45:51 +0200
commitefc6d9951b8abf4095f79a72f37e3a61c3607299 (patch)
tree7a1f54c33cab5ceb4258db58c8fd5e2e739bdcef
parent99b870d61c0a574011d16886d2cea44d18c11a2d (diff)
downloadrneovim-efc6d9951b8abf4095f79a72f37e3a61c3607299.tar.gz
rneovim-efc6d9951b8abf4095f79a72f37e3a61c3607299.tar.bz2
rneovim-efc6d9951b8abf4095f79a72f37e3a61c3607299.zip
win,fs.c: Fix is_executable_ext #10209
Fix issue that increment expression is executable and pointer ext pointing out of the buffer, if the pointer ext points to the terminating NUL. * Change termination condition judgment to one place * Change first condition judgment Change to not evaluate *(ext -1) in the first condition judgment. * Change to use copy_option_part instead of STRLCPY
-rw-r--r--src/nvim/os/fs.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 1ecca87cde..65362b545f 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -24,6 +24,7 @@
#include "nvim/message.h"
#include "nvim/assert.h"
#include "nvim/misc1.h"
+#include "nvim/option.h"
#include "nvim/path.h"
#include "nvim/strings.h"
@@ -312,7 +313,8 @@ static bool is_executable_ext(char *name, char_u **abspath)
if (!pathext) {
pathext = ".com;.exe;.bat;.cmd";
}
- for (const char *ext = pathext; *ext; ext++) {
+ const char *ext = pathext;
+ while (*ext) {
// If $PATHEXT itself contains dot:
if (ext[0] == '.' && (ext[1] == '\0' || ext[1] == ENV_SEPCHAR)) {
if (is_executable(name, abspath)) {
@@ -320,13 +322,17 @@ static bool is_executable_ext(char *name, char_u **abspath)
}
// Skip it.
ext++;
+ if (*ext) {
+ ext++;
+ }
continue;
}
- const char *ext_end = xstrchrnul(ext, ENV_SEPCHAR);
- size_t ext_len = (size_t)(ext_end - ext);
+ const char *ext_end = ext;
+ size_t ext_len =
+ copy_option_part((char_u **)&ext_end, (char_u *)buf_end,
+ sizeof(os_buf) - (size_t)(buf_end - os_buf), ENV_SEPSTR);
if (ext_len != 0) {
- STRLCPY(buf_end, ext, ext_len + 1);
bool in_pathext = nameext_len == ext_len
&& 0 == mb_strnicmp((char_u *)nameext, (char_u *)ext, ext_len);