-
Notifications
You must be signed in to change notification settings - Fork 3
fixes issues found by static analysis tools #94
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wooooooow, nice work 🍩!
Thanks a lot, I have nothing to add 🎉.
Will approve it as soon as we finished discussing what we do (fixing or ignore with reason) with the remaining two issues in the tokenlib.
@DonatJR I´ll have a look at those issues and push directly into this PR if I may 😉 |
@bencikpeter Sure, go ahead |
@DonatJR could you please send me a full report? (I am not a HTWG student anymore, so no VPN 😞). I don´t quite understand what exactly the error is trying to say... I don´t throw any exeptions manually with tokenTemplate::tokenTemplate(HANDLE &userToken) {
//load internal NtCreateToken function
HMODULE hModule = LoadLibrary(L"ntdll.dll");
NtCreateToken = (NT_CREATE_TOKEN)GetProcAddress(hModule, "NtCreateToken");
//parse token
DWORD bufferSize = 0;
GetTokenInformation(userToken, TokenType, NULL, 0, &bufferSize);
SetLastError(0);
GetTokenInformation(userToken, TokenType, (LPVOID)&tokenType, bufferSize, &bufferSize);
if (GetLastError() != 0)
{
throw TokenParsingException();
}
bufferSize = 0;
GetTokenInformation(userToken, TokenUser, NULL, 0, &bufferSize);
SetLastError(0);
tokenUser = (PTOKEN_USER) new BYTE[bufferSize];
GetTokenInformation(userToken, TokenUser, (LPVOID)tokenUser, bufferSize, &bufferSize);
if (GetLastError() != 0)
{
throw TokenParsingException();
} |
Since probable nature of exceptions will be runtime and I believe should not be handled directly inside the function, to address the resource leak, this should suffice: for (auto const& processPid : processes)
{
HANDLE processHandle;
if ((processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processPid)) == NULL) continue;
try
{
if (processIsLocalSystem(processHandle))
{
return processHandle;
}
}
catch (const std::exception&)
{
CloseHandle(processHandle);
throw;
}
CloseHandle(processHandle);
} |
@bencikpeter Unfortunately, I don't know how to get a pdf report from the website based static analysis tool these errors are from, sorry. :/ The exception probably stems from a call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
@bencikpeter There were some issues found in the
tokenLib
as well, here are all issues which I fixed in this PR:There were also two issues I did not yet fix (as I wasn't sure how to proceed):
As you can see the handles returned from
OpenProcess
are not closed ifhasSeCreateTokenPrivilege
orprocessIsLocalSystem
throw an exception. I was not sure if you did not catch those on purpose. Any suggestions on the easiest way to deal with these issues? Do you want to do it yourself? (Maybe they are not even relevant anymore after #91?)