Improve token error checking
@@ -522,13 +522,13 @@ BOOLEAN PhpUpdateTokenGroups(
_In_ HANDLE TokenHandle
)
{
- PTOKEN_GROUPS groups;
+ PTOKEN_GROUPS groups = NULL;
PTOKEN_GROUPS restrictedSIDs = NULL;
- if (!NT_SUCCESS(PhGetTokenGroups(TokenHandle, &groups)))
- return FALSE;
-
+ if (NT_SUCCESS(PhGetTokenGroups(TokenHandle, &groups)))
+ {
PhpUpdateSidsFromTokenGroups(ListViewHandle, groups, FALSE);
+ }
if (NT_SUCCESS(PhGetTokenRestrictedSids(TokenHandle, &restrictedSIDs)))
{
@@ -537,12 +537,10 @@ BOOLEAN PhpUpdateTokenGroups(
if (TokenPageContext->RestrictedSids)
PhFree(TokenPageContext->RestrictedSids);
-
- TokenPageContext->RestrictedSids = restrictedSIDs;
-
if (TokenPageContext->Groups)
PhFree(TokenPageContext->Groups);
+ TokenPageContext->RestrictedSids = restrictedSIDs;
TokenPageContext->Groups = groups;
return TRUE;
@@ -994,6 +992,8 @@ INT_PTR CALLBACK PhpTokenPageProc(
listViewItems[i]
);
+ if (lvItemIndex != -1)
+ {
if (GET_WM_COMMAND_ID(wParam, lParam) != ID_PRIVILEGE_REMOVE)
{
// Refresh the status text (and background color).
@@ -1013,6 +1013,7 @@ INT_PTR CALLBACK PhpTokenPageProc(
);
}
}
+ }
else
{
PWSTR action = L"set";
@@ -1127,13 +1128,18 @@ INT_PTR CALLBACK PhpTokenPageProc(
newAttributes
)))
{
- PPH_STRING attributesString = PhGetGroupAttributesString(newAttributes, FALSE);
- INT lvItemIndex = PhFindListViewItemByParam(
+ PPH_STRING attributesString;
+ INT lvItemIndex;
+
+ attributesString = PhGetGroupAttributesString(newAttributes, FALSE);
+ lvItemIndex = PhFindListViewItemByParam(
tokenPageContext->ListViewHandle,
-1,
listViewItems[i]
);
+ if (lvItemIndex != -1)
+ {
// Refresh the status text (and background color).
listViewItems[i]->TokenGroup->Attributes = newAttributes;
PhSetListViewSubItem(
@@ -1142,6 +1148,8 @@ INT_PTR CALLBACK PhpTokenPageProc(
PH_PROCESS_TOKEN_INDEX_STATUS,
attributesString->Buffer
);
+ }
+
PhDereferenceObject(attributesString);
}
else
@@ -1243,8 +1251,11 @@ INT_PTR CALLBACK PhpTokenPageProc(
listViewItems[0]
);
+ if (lvItemIndex != -1)
+ {
ListView_DeleteItem(tokenPageContext->ListViewHandle, lvItemIndex);
}
+ }
else
{
PhShowStatus(hwndDlg, L"Unable to disable UIAccess flag.", status, 0);
