Skip to content

Commit

Permalink
fix proctree leak and use of uninitialized data
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Jan 1, 2025
1 parent 8a4189a commit 417c944
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 66 deletions.
48 changes: 28 additions & 20 deletions SystemInformer/mainwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1749,11 +1749,13 @@ VOID PhMwpOnCommand(
PPH_PROCESS_ITEM *processes;
ULONG numberOfProcesses;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);
PhReferenceObjects(processes, numberOfProcesses);
PhUiReduceWorkingSetProcesses(WindowHandle, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PhReferenceObjects(processes, numberOfProcesses);
PhUiReduceWorkingSetProcesses(WindowHandle, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
}
}
break;
case ID_MISCELLANEOUS_RUNAS:
Expand Down Expand Up @@ -1805,11 +1807,13 @@ VOID PhMwpOnCommand(
PPH_PROCESS_ITEM* processes;
ULONG numberOfProcesses;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);
PhReferenceObjects(processes, numberOfProcesses);
PhUiFlushHeapProcesses(WindowHandle, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PhReferenceObjects(processes, numberOfProcesses);
PhUiFlushHeapProcesses(WindowHandle, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
}
}
break;
case ID_PRIORITY_REALTIME:
Expand All @@ -1822,11 +1826,13 @@ VOID PhMwpOnCommand(
PPH_PROCESS_ITEM *processes;
ULONG numberOfProcesses;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);
PhReferenceObjects(processes, numberOfProcesses);
PhMwpExecuteProcessPriorityCommand(WindowHandle, Id, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PhReferenceObjects(processes, numberOfProcesses);
PhMwpExecuteProcessPriorityCommand(WindowHandle, Id, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
}
}
break;
case ID_IOPRIORITY_VERYLOW:
Expand All @@ -1837,11 +1843,13 @@ VOID PhMwpOnCommand(
PPH_PROCESS_ITEM *processes;
ULONG numberOfProcesses;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);
PhReferenceObjects(processes, numberOfProcesses);
PhMwpExecuteProcessIoPriorityCommand(WindowHandle, Id, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PhReferenceObjects(processes, numberOfProcesses);
PhMwpExecuteProcessIoPriorityCommand(WindowHandle, Id, processes, numberOfProcesses);
PhDereferenceObjects(processes, numberOfProcesses);
PhFree(processes);
}
}
break;
case ID_MISCELLANEOUS_ECOMODE:
Expand Down
8 changes: 3 additions & 5 deletions SystemInformer/mwpgproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,7 @@ VOID PhShowProcessContextMenu(
PPH_PROCESS_ITEM *processes;
ULONG numberOfProcesses;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);

if (numberOfProcesses != 0)
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PPH_EMENU menu;
PPH_EMENU_ITEM item;
Expand Down Expand Up @@ -1025,9 +1023,9 @@ VOID PhShowProcessContextMenu(
}

PhDestroyEMenu(menu);
}

PhFree(processes);
PhFree(processes);
}
}

VOID NTAPI PhMwpProcessAddedHandler(
Expand Down
3 changes: 3 additions & 0 deletions SystemInformer/proctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -5286,6 +5286,9 @@ BOOLEAN PhGetSelectedProcessItems(
}
else
{
*NumberOfProcesses = 0;
*Processes = NULL;
PhDeleteArray(&array);
return FALSE;
}
}
Expand Down
88 changes: 47 additions & 41 deletions plugins/UserNotes/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1693,27 +1693,29 @@ VOID NTAPI MenuHookCallback(
ULONG numberOfProcesses;
ULONG i;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);
LockDb();

for (i = 0; i < numberOfProcesses; i++)
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PDB_OBJECT object;
LockDb();

if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PRIORITY_CLASS))
for (i = 0; i < numberOfProcesses; i++)
{
ULONG newPriorityClass = GetPriorityClassFromId(id);
PDB_OBJECT object;

if (object->PriorityClass != newPriorityClass)
if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PRIORITY_CLASS))
{
object->PriorityClass = newPriorityClass;
changed = TRUE;
ULONG newPriorityClass = GetPriorityClassFromId(id);

if (object->PriorityClass != newPriorityClass)
{
object->PriorityClass = newPriorityClass;
changed = TRUE;
}
}
}
}

UnlockDb();
PhFree(processes);
UnlockDb();
PhFree(processes);
}

if (changed)
SaveDb();
Expand All @@ -1729,27 +1731,29 @@ VOID NTAPI MenuHookCallback(
ULONG numberOfProcesses;
ULONG i;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);
LockDb();

for (i = 0; i < numberOfProcesses; i++)
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PDB_OBJECT object;
LockDb();

if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_IO_PRIORITY))
for (i = 0; i < numberOfProcesses; i++)
{
ULONG newIoPriorityPlusOne = GetIoPriorityFromId(id) + 1;
PDB_OBJECT object;

if (object->IoPriorityPlusOne != newIoPriorityPlusOne)
if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_IO_PRIORITY))
{
object->IoPriorityPlusOne = newIoPriorityPlusOne;
changed = TRUE;
ULONG newIoPriorityPlusOne = GetIoPriorityFromId(id) + 1;

if (object->IoPriorityPlusOne != newIoPriorityPlusOne)
{
object->IoPriorityPlusOne = newIoPriorityPlusOne;
changed = TRUE;
}
}
}
}

UnlockDb();
PhFree(processes);
UnlockDb();
PhFree(processes);
}

if (changed)
SaveDb();
Expand All @@ -1766,27 +1770,29 @@ VOID NTAPI MenuHookCallback(
ULONG numberOfProcesses;
ULONG i;

PhGetSelectedProcessItems(&processes, &numberOfProcesses);
LockDb();

for (i = 0; i < numberOfProcesses; i++)
if (PhGetSelectedProcessItems(&processes, &numberOfProcesses))
{
PDB_OBJECT object;
LockDb();

if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PAGEPRIORITY))
for (i = 0; i < numberOfProcesses; i++)
{
ULONG newPagePriorityPlusOne = GetPagePriorityFromId(id) + 1;
PDB_OBJECT object;

if (object->PagePriorityPlusOne != newPagePriorityPlusOne)
if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PAGEPRIORITY))
{
object->PagePriorityPlusOne = newPagePriorityPlusOne;
changed = TRUE;
ULONG newPagePriorityPlusOne = GetPagePriorityFromId(id) + 1;

if (object->PagePriorityPlusOne != newPagePriorityPlusOne)
{
object->PagePriorityPlusOne = newPagePriorityPlusOne;
changed = TRUE;
}
}
}
}

UnlockDb();
PhFree(processes);
UnlockDb();
PhFree(processes);
}

if (changed)
SaveDb();
Expand Down Expand Up @@ -1997,7 +2003,7 @@ VOID TreeNewMessageCallback(
}
break;
}

}
else if (message->TreeNewHandle == ServiceTreeNewHandle)
{
Expand Down Expand Up @@ -2345,7 +2351,7 @@ VOID ProcessTreeNewInitializingCallback(
affinity.Text = L"Affinity";
affinity.Width = 120;
affinity.Alignment = PH_ALIGN_LEFT;

PhPluginAddTreeNewColumn(PluginInstance, info->CmData, &column, COMMENT_COLUMN_ID, NULL, ProcessCommentSortFunction);
PhPluginAddTreeNewColumn(PluginInstance, info->CmData, &affinity, AFFINITY_COLUMN_ID, NULL, ProcessAffinitySortFunction);
}
Expand Down

0 comments on commit 417c944

Please sign in to comment.