kernel32: Check that sysctl() call succeeded before using its output.

This commit is contained in:
Ken Thomases 2014-02-16 20:43:28 -06:00 committed by Alexandre Julliard
parent aa22a3c4b2
commit 89a96db01f

View File

@ -1222,12 +1222,12 @@ BOOL WINAPI GlobalMemoryStatusEx( LPMEMORYSTATUSEX lpmemex )
mib[0] = CTL_HW;
mib[1] = HW_PHYSMEM;
size_sys = sizeof(val);
sysctl(mib, 2, &val, &size_sys, NULL, 0);
if (val) lpmemex->ullTotalPhys = val;
if (!sysctl(mib, 2, &val, &size_sys, NULL, 0) && size_sys == sizeof(val) && val)
lpmemex->ullTotalPhys = val;
mib[1] = HW_USERMEM;
size_sys = sizeof(val);
sysctl(mib, 2, &val, &size_sys, NULL, 0);
if (!val) val = lpmemex->ullTotalPhys;
if (sysctl(mib, 2, &val, &size_sys, NULL, 0) || size_sys != sizeof(val) || !val)
val = lpmemex->ullTotalPhys;
lpmemex->ullAvailPhys = val;
lpmemex->ullTotalPageFile = val;
lpmemex->ullAvailPageFile = val;