]> granicus.if.org Git - vim/commitdiff
patch 8.1.1095: MS-Windows: executable() fails on very long filename v8.1.1095
authorBram Moolenaar <Bram@vim.org>
Sat, 30 Mar 2019 20:51:28 +0000 (21:51 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 30 Mar 2019 20:51:28 +0000 (21:51 +0100)
Problem:    MS-Windows: executable() fails on very long filename.
Solution:   (Ken Takata, closes #4015)

src/os_win32.c
src/testdir/test_functions.vim
src/version.c

index fe729d4de20d3eabbf089b4e05fd92876e239f88..c0d6ad77bddc3dc937b0f3ca3b1e6c1998ed50ca 100644 (file)
@@ -3299,14 +3299,17 @@ mch_writable(char_u *name)
     int
 mch_can_exe(char_u *name, char_u **path, int use_path)
 {
-    char_u     buf[_MAX_PATH];
+    // WinNT and later can use _MAX_PATH wide characters for a pathname, which
+    // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is
+    // UTF-8.
+    char_u     buf[_MAX_PATH * 3];
     int                len = (int)STRLEN(name);
     char_u     *p, *saved;
 
-    if (len >= _MAX_PATH)      /* safety check */
+    if (len >= sizeof(buf))    // safety check
        return FALSE;
 
-    /* Ty using the name directly when a Unix-shell like 'shell'. */
+    // Try using the name directly when a Unix-shell like 'shell'.
     if (strstr((char *)gettail(p_sh), "sh") != NULL)
        if (executable_exists((char *)name, path, use_path))
            return TRUE;
@@ -3339,7 +3342,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
     }
     vim_free(saved);
 
-    vim_strncpy(buf, name, _MAX_PATH - 1);
+    vim_strncpy(buf, name, sizeof(buf) - 1);
     p = mch_getenv("PATHEXT");
     if (p == NULL)
        p = (char_u *)".com;.exe;.bat;.cmd";
@@ -3354,7 +3357,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
                ++p;
        }
        else
-           copy_option_part(&p, buf + len, _MAX_PATH - len, ";");
+           copy_option_part(&p, buf + len, sizeof(buf) - len, ";");
        if (executable_exists((char *)buf, path, use_path))
            return TRUE;
     }
index 63f477db9a23d0eb2eac846630449ec5c6961c69..e273e8aa799cb791b5b5d79ae4f9eccd52c01788 100644 (file)
@@ -944,6 +944,17 @@ func Test_Executable()
   endif
 endfunc
 
+func Test_executable_longname()
+  if !has('win32')
+    return
+  endif
+
+  let fname = 'X' . repeat('あ', 200) . '.bat'
+  call writefile([], fname)
+  call assert_equal(1, executable(fname))
+  call delete(fname)
+endfunc
+
 func Test_hostname()
   let hostname_vim = hostname()
   if has('unix')
index 9ba9e92d0cd85fc6e199425c4ffa1e40fd5bf760..3e675fcdea27d7be98f6f810c8ccf9a57887c5df 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1095,
 /**/
     1094,
 /**/