diff src/os_mswin.c @ 16945:efd36a9052cc v8.1.1473

patch 8.1.1473: new resolve() implementation causes problem for plugins commit https://github.com/vim/vim/commit/4a792c87b9a643a949ee36106a2f7e971dc633f8 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 6 12:22:41 2019 +0200 patch 8.1.1473: new resolve() implementation causes problem for plugins Problem: New resolve() implementation causes problem for plugins. Solution: Only resolve a resparse point after checking it is needed. (Ken Takata, closes #4492)
author Bram Moolenaar <Bram@vim.org>
date Thu, 06 Jun 2019 12:30:05 +0200
parents f42aa3d90b12
children a6f392cc9587
line wrap: on
line diff
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -1753,6 +1753,39 @@ typedef BOOL (WINAPI *pfnGetVolumeInform
 	DWORD	nFileSystemNameSize);
 static pfnGetVolumeInformationByHandleW pGetVolumeInformationByHandleW = NULL;
 
+# define is_path_sep(c)	    ((c) == L'\\' || (c) == L'/')
+
+    static int
+is_reparse_point_included(LPCWSTR fname)
+{
+    LPCWSTR	p = fname, q;
+    WCHAR	buf[MAX_PATH];
+    DWORD	attr;
+
+    if (isalpha(p[0]) && p[1] == L':' && is_path_sep(p[2]))
+	p += 3;
+    else if (is_path_sep(p[0]) && is_path_sep(p[1]))
+	p += 2;
+
+    while (*p != L'\0')
+    {
+	q = wcspbrk(p, L"\\/");
+	if (q == NULL)
+	    p = q = fname + wcslen(fname);
+	else
+	    p = q + 1;
+	if (q - fname >= MAX_PATH)
+	    return FALSE;
+	wcsncpy(buf, fname, q - fname);
+	buf[q - fname] = L'\0';
+	attr = GetFileAttributesW(buf);
+	if (attr != INVALID_FILE_ATTRIBUTES
+		&& (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0)
+	    return TRUE;
+    }
+    return FALSE;
+}
+
     static char_u *
 resolve_reparse_point(char_u *fname)
 {
@@ -1787,6 +1820,12 @@ resolve_reparse_point(char_u *fname)
     if (p == NULL)
 	goto fail;
 
+    if (!is_reparse_point_included(p))
+    {
+	vim_free(p);
+	goto fail;
+    }
+
     h = CreateFileW(p, 0, 0, NULL, OPEN_EXISTING,
 	    FILE_FLAG_BACKUP_SEMANTICS, NULL);
     vim_free(p);