I have the following program written in C:
#include "stdafx.h"
#include <Windows.h>
void main()
{
char buffer[1000];
int size = sizeof(buffer);
PDWORD required_size;
printf("----Application Privileges----\n\n");
printf("In this program, we are going to obtain information about the application privileges\n\n");
HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, GetCurrentProcessId()); //Opening the current process
HANDLE token; //Creating a handle for the token
OpenProcessToken(process, TOKEN_ADJUST_PRIVILEGES, &token); //Opening the process token
GetTokenInformation(token, TokenPrivileges, buffer, size, required_size); //Obtaining the token information
printf("The following information was obtained with regards to the token privileges: \n\n");
printf("%s\n\n", buffer);
printf("Press enter to exit the program");
getchar();
}
Now, I am relatively new to the use of tokens. When I try to execute the program, the following error comes up:
Run-Time Check Failure #3 – The variable ‘required_size’ is being used without being initialized.
How can I solve this problem please? What I want to do is to display information about the token privileges of the current process to the user.
I don’t know exactly what the last variable (ReturnLength [out]) in the GetTokenInformation method does. I tried reading the msdn documentation but did not understand its use.
Check the example and detailed explanation I gave you again. You need to find the length of the buffer first. Then initialize your buffer to exactly the size of the TOKEN_PRIVILEGES structure that you get. Here’s the line that does initialization: