Make GetProcessMemoryInfo fail if the passed buffer is too small.
This commit is contained in:
parent
281eb29e12
commit
08200ca3bc
|
@ -516,14 +516,20 @@ DWORD WINAPI GetProcessImageFileNameW( HANDLE process, LPWSTR file, DWORD size )
|
||||||
* Retrieve memory usage information for a given process
|
* Retrieve memory usage information for a given process
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI GetProcessMemoryInfo( HANDLE process, PPROCESS_MEMORY_COUNTERS counters, DWORD size )
|
BOOL WINAPI GetProcessMemoryInfo(HANDLE hProcess,
|
||||||
|
PPROCESS_MEMORY_COUNTERS pmc, DWORD cb)
|
||||||
{
|
{
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
VM_COUNTERS vmc;
|
VM_COUNTERS vmc;
|
||||||
|
|
||||||
TRACE( "(%p, %p, %ld)\n", process, counters, size );
|
if (cb < sizeof(PROCESS_MEMORY_COUNTERS))
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
status = NtQueryInformationProcess( process, ProcessVmCounters, &vmc, sizeof(vmc), NULL );
|
status = NtQueryInformationProcess(hProcess, ProcessVmCounters,
|
||||||
|
&vmc, sizeof(vmc), NULL);
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
|
@ -531,18 +537,16 @@ BOOL WINAPI GetProcessMemoryInfo( HANDLE process, PPROCESS_MEMORY_COUNTERS count
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: check size */
|
pmc->cb = sizeof(PROCESS_MEMORY_COUNTERS);
|
||||||
|
pmc->PageFaultCount = vmc.PageFaultCount;
|
||||||
counters->cb = sizeof(PROCESS_MEMORY_COUNTERS);
|
pmc->PeakWorkingSetSize = vmc.PeakWorkingSetSize;
|
||||||
counters->PageFaultCount = vmc.PageFaultCount;
|
pmc->WorkingSetSize = vmc.WorkingSetSize;
|
||||||
counters->PeakWorkingSetSize = vmc.PeakWorkingSetSize;
|
pmc->QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage;
|
||||||
counters->WorkingSetSize = vmc.WorkingSetSize;
|
pmc->QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage;
|
||||||
counters->QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage;
|
pmc->QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage;
|
||||||
counters->QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage;
|
pmc->QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage;
|
||||||
counters->QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage;
|
pmc->PagefileUsage = vmc.PagefileUsage;
|
||||||
counters->QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage;
|
pmc->PeakPagefileUsage = vmc.PeakPagefileUsage;
|
||||||
counters->PagefileUsage = vmc.PagefileUsage;
|
|
||||||
counters->PeakPagefileUsage = vmc.PeakPagefileUsage;
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ static void test_GetProcessMemoryInfo(void)
|
||||||
|
|
||||||
w32_err(pGetProcessMemoryInfo(NULL, &pmc, sizeof(pmc)), ERROR_INVALID_HANDLE);
|
w32_err(pGetProcessMemoryInfo(NULL, &pmc, sizeof(pmc)), ERROR_INVALID_HANDLE);
|
||||||
todo_wine w32_err(pGetProcessMemoryInfo(hpSR, &pmc, sizeof(pmc)), ERROR_ACCESS_DENIED);
|
todo_wine w32_err(pGetProcessMemoryInfo(hpSR, &pmc, sizeof(pmc)), ERROR_ACCESS_DENIED);
|
||||||
todo_wine w32_err(pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)-1), ERROR_INSUFFICIENT_BUFFER);
|
w32_err(pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)-1), ERROR_INSUFFICIENT_BUFFER);
|
||||||
w32_suc(pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)));
|
w32_suc(pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue