Merge pull request #2387 from LukeUsher/fix-heap-corruption-at-startup-with-nvnet

Fix heap corruption in NVNetDevice::GetMacAddress
This commit is contained in:
Luke Usher 2022-07-13 09:36:31 +01:00 committed by GitHub
commit 8fcc2f5e0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -537,12 +537,14 @@ void NVNetDevice::Reset()
bool NVNetDevice::GetMacAddress(std::string adapterName, void* pMAC)
{
// AdapterInfo is too large to be allocated on the stack, and will cause a crash in debug builds when _chkstk detects it
PIP_ADAPTER_INFO pAdapterInfo = new IP_ADAPTER_INFO[128];
auto adapterInfo = new IP_ADAPTER_INFO[128];
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)adapterInfo;
ULONG dwBufferLength = sizeof(IP_ADAPTER_INFO) * 128;
DWORD dwStatus = GetAdaptersInfo(pAdapterInfo, &dwBufferLength);
if (dwStatus != ERROR_SUCCESS) {
delete[] pAdapterInfo;
delete[] adapterInfo;
return false;
}
@ -550,7 +552,7 @@ bool NVNetDevice::GetMacAddress(std::string adapterName, void* pMAC)
do {
if (strcmp(pAdapterInfo->AdapterName, adapterName.c_str()) == 0) {
memcpy(pMAC, pAdapterInfo->Address, 6);
delete[] pAdapterInfo;
delete[] adapterInfo;
return true;
}
@ -558,7 +560,7 @@ bool NVNetDevice::GetMacAddress(std::string adapterName, void* pMAC)
} while (pAdapterInfo);
delete[] pAdapterInfo;
delete[] adapterInfo;
return false;
}