]> mj.ucw.cz Git - pciutils.git/commitdiff
windows: Correctly propagate error code from win32_call_func_with_tcb_privilege()
authorPali Rohár <pali@kernel.org>
Wed, 28 Feb 2024 00:06:38 +0000 (01:06 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 5 Apr 2024 11:14:04 +0000 (13:14 +0200)
Cleanup phase may change error code as it calls other WinAPI functions.

lib/win32-helpers.c

index d370d5cbaab61e9de9d995f190b048f51c41c40e..5338efa21b3faab9eddc6d6cc5d347d852e1383d 100644 (file)
@@ -1227,6 +1227,7 @@ win32_call_func_with_tcb_privilege(BOOL (*function)(LPVOID), LPVOID argument)
   HANDLE lsass_process;
   HANDLE lsass_token;
 
+  DWORD error;
   BOOL ret;
 
   impersonate_privilege_enabled = FALSE;
@@ -1374,6 +1375,8 @@ err_privilege_not_held:
   goto ret;
 
 ret:
+  error = GetLastError();
+
   if (revert_to_old_token)
     win32_revert_to_token(old_token);
 
@@ -1383,5 +1386,7 @@ ret:
   if (lsass_token)
     CloseHandle(lsass_token);
 
+  SetLastError(error);
+
   return ret;
 }