Skip to content

Commit

Permalink
[WASimClient] Fix incoming data size check for variable requests whic…
Browse files Browse the repository at this point in the history
…h are less than 4 bytes in size.
  • Loading branch information
mpaperno committed Oct 22, 2023
1 parent 682ceff commit c8e74df
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/WASimClient/WASimClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,8 @@ class WASimClient::Private
case SIMCONNECT_RECV_ID_CLIENT_DATA: {
SIMCONNECT_RECV_CLIENT_DATA* data = (SIMCONNECT_RECV_CLIENT_DATA*)pData;
LOG_TRC << LOG_SC_RCV_CLIENT_DATA(data);
const size_t dataSize = (size_t)pData->dwSize + 4 - sizeof(SIMCONNECT_RECV_CLIENT_DATA); // dwSize reports 4 bytes less than actual size of SIMCONNECT_RECV_CLIENT_DATA
// dwSize always under-reports by 4 bytes when sizeof(SIMCONNECT_RECV_CLIENT_DATA) is subtracted, and the minimum reported size is 4 bytes even for 0-3 bytes of actual data.
const size_t dataSize = (size_t)pData->dwSize + 4 - sizeof(SIMCONNECT_RECV_CLIENT_DATA);
switch (data->dwRequestID)
{
case DATA_REQ_RESPONSE: {
Expand Down Expand Up @@ -1355,12 +1356,11 @@ class WASimClient::Private
LOG_WRN << "DataRequest ID " << data->dwRequestID - SIMCONNECTID_LAST << " not found in tracked requests.";
return;
}
// be paranoid
if (dataSize != tr->dataSize) {
// be paranoid; note that the reported pData->dwSize is never less than 4 bytes.
if (dataSize < tr->dataSize) {
LOG_CRT << "Invalid data result size! Expected " << tr->dataSize << " but got " << dataSize;
return;
}
//unique_lock lock(mtxRequests);
unique_lock datalock(tr->m_dataMutex);
memcpy(tr->data.data(), (void*)&data->dwData, tr->dataSize);
tr->lastUpdate = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
Expand Down

0 comments on commit c8e74df

Please sign in to comment.