[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
This commit is contained in:
Serge Gautherie 2020-07-21 14:39:11 +02:00 committed by GitHub
parent b338fb7beb
commit 98bbe8358c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 12 deletions

View file

@ -65,7 +65,7 @@ RunningAsSYSTEM(VOID)
return FALSE; return FALSE;
/* Retrieve token's information */ /* Retrieve token's information */
if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &cbTokenBuffer) && if (GetTokenInformation(hToken, TokenUser, NULL, 0, &cbTokenBuffer) ||
GetLastError() != ERROR_INSUFFICIENT_BUFFER) GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{ {
goto Quit; goto Quit;

View file

@ -53,14 +53,14 @@ DwInitializeSdFromThreadToken (
} }
/* Get the size of the token's user */ /* 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)) (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
{ {
return GetLastError(); return GetLastError();
} }
/* Get the size of the token's primary group */ /* 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)) (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
{ {
return GetLastError(); return GetLastError();

View file

@ -695,9 +695,11 @@ AddUserProfiles(
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
return; return;
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize); if (GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize) ||
if (dwSize == 0) GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
goto done; goto done;
}
pTokenUser = HeapAlloc(GetProcessHeap(), 0, dwSize); pTokenUser = HeapAlloc(GetProcessHeap(), 0, dwSize);
if (pTokenUser == NULL) if (pTokenUser == NULL)

View file

@ -179,14 +179,11 @@ IsUserAdmin(VOID)
&hToken)) &hToken))
goto done; goto done;
dwSize = 0; if (GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize) ||
GetTokenInformation(hToken, GetLastError() != ERROR_INSUFFICIENT_BUFFER)
TokenGroups, {
NULL,
0,
&dwSize);
if (dwSize == 0)
goto done; goto done;
}
pGroups = HeapAlloc(GetProcessHeap(), 0, dwSize); pGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
if (pGroups == NULL) if (pGroups == NULL)