Use pldm_msg_hdr_correlate_response()
This call to ensure the PLDM response matches the PLDM request for the
HRESET, OCC Reset, and Sensor Status requests.
If it does not match, the response is ignored.
Tested on Rainier
Change-Id: Id072aa79518752c11eb0f3108cd4066cfa1baa85
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/pldm.cpp b/pldm.cpp
index 7c38971..b96b8eb 100644
--- a/pldm.cpp
+++ b/pldm.cpp
@@ -734,6 +734,10 @@
return;
}
+ // Save header to confirm response matches
+ auto requestPtr = reinterpret_cast<const pldm_msg*>(&request[0]);
+ memcpy(&_requestHeader, requestPtr, sizeof(pldm_msg_hdr));
+
// start timer waiting for the response
pldmRspTimer.restartOnce(timeout);
@@ -874,7 +878,7 @@
auto rc = pldm_transport_recv_msg(pldmIface->pldmTransport, &pldmTID,
(void**)&responseMsg, &responseMsgSize);
int lastErrno = errno;
- if (rc)
+ if (rc != PLDM_REQUESTER_SUCCESS)
{
if (!throttleTraces)
{
@@ -888,6 +892,15 @@
return -1;
}
+ // Verify the response header matches our request
+ struct pldm_msg_hdr* hdr = (struct pldm_msg_hdr*)responseMsg;
+ if ((pldmTID != mctpEid) ||
+ !pldm_msg_hdr_correlate_response(&pldmIface->_requestHeader, hdr))
+ {
+ // We got a response to someone else's message. Ignore it.
+ return 0;
+ }
+
// We got the response for the PLDM request msg that was sent
if (!throttleTraces)
{
@@ -1013,7 +1026,7 @@
auto rc = pldm_transport_recv_msg(pldmIface->pldmTransport, &pldmTID,
(void**)&responseMsg, &responseMsgSize);
int lastErrno = errno;
- if (rc)
+ if (rc != PLDM_REQUESTER_SUCCESS)
{
if (!throttleTraces)
{
@@ -1027,6 +1040,15 @@
return -1;
}
+ // Verify the response header matches our request
+ struct pldm_msg_hdr* hdr = (struct pldm_msg_hdr*)responseMsg;
+ if ((pldmTID != mctpEid) ||
+ !pldm_msg_hdr_correlate_response(&pldmIface->_requestHeader, hdr))
+ {
+ // We got a response to someone else's message. Ignore it.
+ return 0;
+ }
+
// We got the response for the PLDM request msg that was sent
if (!throttleTraces)
{