https://git.reactos.org/?p=reactos.git;a=commitdiff;h=98bbe8358caceeacfb069d8f6daef51b5476e93b

commit 98bbe8358caceeacfb069d8f6daef51b5476e93b
Author:     Serge Gautherie <[email protected]>
AuthorDate: Tue Jul 21 14:39:11 2020 +0200
Commit:     GitHub <[email protected]>
CommitDate: Tue Jul 21 15:39:11 2020 +0300

    [REACTOS] Fix GetTokenInformation() usage (#2997)
    
    The first call to GetTokenInformation is used to determine the size of a 
TokenInformation buffer.
    It should fail and return ERROR_INSUFFICIENT_BUFFER
---
 base/services/rpcss/setup.c        |  2 +-
 base/services/svchost/security.cxx |  4 ++--
 dll/cpl/sysdm/userprofile.c        |  6 ++++--
 dll/win32/netid/netid.c            | 11 ++++-------
 4 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/base/services/rpcss/setup.c b/base/services/rpcss/setup.c
index e51831efc41..e94a05c9264 100644
--- a/base/services/rpcss/setup.c
+++ b/base/services/rpcss/setup.c
@@ -65,7 +65,7 @@ RunningAsSYSTEM(VOID)
         return FALSE;
 
     /* Retrieve token's information */
-    if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &cbTokenBuffer) &&
+    if (GetTokenInformation(hToken, TokenUser, NULL, 0, &cbTokenBuffer) ||
         GetLastError() != ERROR_INSUFFICIENT_BUFFER)
     {
         goto Quit;
diff --git a/base/services/svchost/security.cxx 
b/base/services/svchost/security.cxx
index 0dfb9adf222..451d6c2929a 100644
--- a/base/services/svchost/security.cxx
+++ b/base/services/svchost/security.cxx
@@ -53,14 +53,14 @@ DwInitializeSdFromThreadToken (
     }
 
     /* Get the size of the token's user */
-    if ((GetTokenInformation(hToken, TokenUser, NULL, 0, &dwUserLength) == 
FALSE) ||
+    if ((GetTokenInformation(hToken, TokenUser, NULL, 0, &dwUserLength) != 
FALSE) ||
         (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
     {
         return GetLastError();
     }
 
     /* Get the size of the token's primary group */
-    if ((GetTokenInformation(hToken, TokenPrimaryGroup, NULL, 0, 
&dwGroupLength) == FALSE) ||
+    if ((GetTokenInformation(hToken, TokenPrimaryGroup, NULL, 0, 
&dwGroupLength) != FALSE) ||
         (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
     {
         return GetLastError();
diff --git a/dll/cpl/sysdm/userprofile.c b/dll/cpl/sysdm/userprofile.c
index 58e35f964bd..79f76b76225 100644
--- a/dll/cpl/sysdm/userprofile.c
+++ b/dll/cpl/sysdm/userprofile.c
@@ -695,9 +695,11 @@ AddUserProfiles(
     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
         return;
 
-    GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
-    if (dwSize == 0)
+    if (GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize) ||
+        GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+    {
         goto done;
+    }
 
     pTokenUser = HeapAlloc(GetProcessHeap(), 0, dwSize);
     if (pTokenUser == NULL)
diff --git a/dll/win32/netid/netid.c b/dll/win32/netid/netid.c
index 2e2a1294525..ce3dfb6f417 100644
--- a/dll/win32/netid/netid.c
+++ b/dll/win32/netid/netid.c
@@ -179,14 +179,11 @@ IsUserAdmin(VOID)
                           &hToken))
         goto done;
 
-    dwSize = 0;
-    GetTokenInformation(hToken,
-                        TokenGroups,
-                        NULL,
-                        0,
-                        &dwSize);
-    if (dwSize == 0)
+    if (GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize) ||
+        GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+    {
         goto done;
+    }
 
     pGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
     if (pGroups == NULL)

Reply via email to