mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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
This commit is contained in:
parent
99b870d61c
commit
efc6d9951b
@ -24,6 +24,7 @@
|
|||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/assert.h"
|
#include "nvim/assert.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
|
#include "nvim/option.h"
|
||||||
#include "nvim/path.h"
|
#include "nvim/path.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
|
||||||
@ -312,7 +313,8 @@ static bool is_executable_ext(char *name, char_u **abspath)
|
|||||||
if (!pathext) {
|
if (!pathext) {
|
||||||
pathext = ".com;.exe;.bat;.cmd";
|
pathext = ".com;.exe;.bat;.cmd";
|
||||||
}
|
}
|
||||||
for (const char *ext = pathext; *ext; ext++) {
|
const char *ext = pathext;
|
||||||
|
while (*ext) {
|
||||||
// If $PATHEXT itself contains dot:
|
// If $PATHEXT itself contains dot:
|
||||||
if (ext[0] == '.' && (ext[1] == '\0' || ext[1] == ENV_SEPCHAR)) {
|
if (ext[0] == '.' && (ext[1] == '\0' || ext[1] == ENV_SEPCHAR)) {
|
||||||
if (is_executable(name, abspath)) {
|
if (is_executable(name, abspath)) {
|
||||||
@ -320,13 +322,17 @@ static bool is_executable_ext(char *name, char_u **abspath)
|
|||||||
}
|
}
|
||||||
// Skip it.
|
// Skip it.
|
||||||
ext++;
|
ext++;
|
||||||
|
if (*ext) {
|
||||||
|
ext++;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ext_end = xstrchrnul(ext, ENV_SEPCHAR);
|
const char *ext_end = ext;
|
||||||
size_t ext_len = (size_t)(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) {
|
if (ext_len != 0) {
|
||||||
STRLCPY(buf_end, ext, ext_len + 1);
|
|
||||||
bool in_pathext = nameext_len == ext_len
|
bool in_pathext = nameext_len == ext_len
|
||||||
&& 0 == mb_strnicmp((char_u *)nameext, (char_u *)ext, ext_len);
|
&& 0 == mb_strnicmp((char_u *)nameext, (char_u *)ext, ext_len);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user