]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0780: MS-Windows: incorrect Win32 error checking v9.1.0780
authorNir Lichtman <nir@lichtman.org>
Sun, 13 Oct 2024 17:44:07 +0000 (19:44 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 13 Oct 2024 17:44:07 +0000 (19:44 +0200)
Problem:  MS-Windows: incorrect Win32 error checking
Solution: fix wrong order of error handling and perform
          some minor refactoring (Nir Lichtman)

In the function that adjusts the process privileges there is a mistake
in which GetLastError is called after CloseHandle, though clearly the
last error check is meant for the privileges related call before hand
and the current state appears like a mistake.

So fix this problem, and also perform the following:

- Remove the static variable done since the PlatformId is only called
  during initialization
- Fix incorrect parameter passed to the Win32 API privileges function

closes: #15845

Signed-off-by: Nir Lichtman <nir@lichtman.org>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/os_win32.c
src/version.c

index 81a31409dbbb77bd1231c0feee6aee2fce14ebfe..eedd0a5aba625353915bec31c07b17a3dc082132 100644 (file)
@@ -918,9 +918,8 @@ null_libintl_wputenv(const wchar_t *envstring UNUSED)
  * Enables or disables the specified privilege.
  */
     static BOOL
-win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable)
+win32_enable_privilege(LPTSTR lpszPrivilege)
 {
-    BOOL               bResult;
     LUID               luid;
     HANDLE             hToken;
     TOKEN_PRIVILEGES   tokenPrivileges;
@@ -937,15 +936,22 @@ win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable)
 
     tokenPrivileges.PrivilegeCount          = 1;
     tokenPrivileges.Privileges[0].Luid       = luid;
-    tokenPrivileges.Privileges[0].Attributes = bEnable ?
-                                                   SE_PRIVILEGE_ENABLED : 0;
+    tokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
-    bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges,
-           sizeof(TOKEN_PRIVILEGES), NULL, NULL);
+    if (!AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, 0, NULL, NULL))
+    {
+       CloseHandle(hToken);
+       return FALSE;
+    }
 
-    CloseHandle(hToken);
+    if (GetLastError() != ERROR_SUCCESS)
+    {
+       CloseHandle(hToken);
+       return FALSE;
+    }
 
-    return bResult && GetLastError() == ERROR_SUCCESS;
+    CloseHandle(hToken);
+    return TRUE;
 }
 #endif
 
@@ -961,15 +967,11 @@ win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable)
     void
 PlatformId(void)
 {
-    static int done = FALSE;
-
-    if (done)
-       return;
-
     OSVERSIONINFO ovi;
 
     ovi.dwOSVersionInfoSize = sizeof(ovi);
-    GetVersionEx(&ovi);
+    if (!GetVersionEx(&ovi))
+        return;
 
 #ifdef FEAT_EVAL
     vim_snprintf(windowsVersion, sizeof(windowsVersion), "%d.%d",
@@ -985,9 +987,9 @@ PlatformId(void)
 
 #ifdef HAVE_ACL
     // Enable privilege for getting or setting SACLs.
-    win32_enable_privilege(SE_SECURITY_NAME, TRUE);
+    if (!win32_enable_privilege(SE_SECURITY_NAME))
+        return;
 #endif
-    done = TRUE;
 }
 #ifdef _MSC_VER
 # pragma warning(pop)
index becaa3e4bddd1a1719a2b53b86c9acb2d54c6b28..76d1889ee50c65ca843ab22cef8632d5fc4c0538 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    780,
 /**/
     779,
 /**/