dsp: platform: Fix decode_set_event_receiver_req()
Per DSP0248 V1.3.0 table13, the heartbeatTimer field shall be omitted
from the request data if eventMessageGlobalEnable is not set to
enableAsyncKeepAlive.
Rework the change in 8c43abb due to the issue found in
openbmc/pldm@35f25949fe4d ("Fix invalid read by adjusting request
size")
gitlint-ignore: B1, UC1
Fixes: 66c7723adbdc ("msgbuf: Enable pldm_msgbuf_extract() into packed members")
Fixes: 9667f5823930 ("platform: pldm_msgbuf for decode_set_event_receiver_req()")
Fixes: 6ef2aa90a793 ("platform: Test invalid heartbeat conditions after assignment")
Fixes: 9c76679224cf ("libpldm: Migrate to subproject")
Change-Id: I7ca50e487b9f1e6c6ea2b34f73c363def8b2d295
Signed-off-by: Gilbert Chen <gilbertc@nvidia.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d357b6c..ee64a01 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -173,6 +173,7 @@
16. dsp: bios: Bounds check encode_set_bios_attribute_current_value_req()
17. dsp: bios_table: Bounds check pldm_bios_table_string_entry_encode()
18. dsp: pdr: Rework test in pldm_entity_association_pdr_extract()
+19. dsp: platform: Fix decode_set_event_receiver_req()
## [0.9.1] - 2024-09-07
diff --git a/include/libpldm/platform.h b/include/libpldm/platform.h
index 7ef48c7..e960c8f 100644
--- a/include/libpldm/platform.h
+++ b/include/libpldm/platform.h
@@ -35,6 +35,10 @@
#define PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES 2
#define PLDM_GET_SENSOR_READING_REQ_BYTES 3
#define PLDM_SET_EVENT_RECEIVER_REQ_BYTES 5
+
+/* Minimum size for request */
+#define PLDM_SET_EVENT_RECEIVER_MIN_REQ_BYTES 3
+
/* Response lengths are inclusive of completion code */
#define PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES 1
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index 065b113..df7ea4a 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -2591,16 +2591,23 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_errno(buf, PLDM_SET_EVENT_RECEIVER_REQ_BYTES,
+ rc = pldm_msgbuf_init_errno(buf, PLDM_SET_EVENT_RECEIVER_MIN_REQ_BYTES,
msg->payload, payload_length);
if (rc) {
return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, event_message_global_enable);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
pldm_msgbuf_extract_p(buf, transport_protocol_type);
pldm_msgbuf_extract_p(buf, event_receiver_address_info);
- pldm_msgbuf_extract_p(buf, heartbeat_timer);
+ if ((*event_message_global_enable ==
+ PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE)) {
+ pldm_msgbuf_extract_p(buf, heartbeat_timer);
+ }
rc = pldm_msgbuf_destroy(buf);
if (rc) {
diff --git a/tests/dsp/platform.cpp b/tests/dsp/platform.cpp
index 2d29445..9c44130 100644
--- a/tests/dsp/platform.cpp
+++ b/tests/dsp/platform.cpp
@@ -3674,6 +3674,17 @@
EXPECT_EQ(transportProtocolType, rettransportProtocolType);
EXPECT_EQ(eventReceiverAddressInfo, reteventReceiverAddressInfo);
EXPECT_EQ(heartbeatTimer, retheartbeatTimer);
+
+ eventMessageGlobalEnable = PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC;
+ req->event_message_global_enable = eventMessageGlobalEnable;
+ rc = decode_set_event_receiver_req(
+ request, PLDM_SET_EVENT_RECEIVER_MIN_REQ_BYTES,
+ &reteventMessageGlobalEnable, &rettransportProtocolType,
+ &reteventReceiverAddressInfo, &retheartbeatTimer);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(eventMessageGlobalEnable, reteventMessageGlobalEnable);
+ EXPECT_EQ(transportProtocolType, rettransportProtocolType);
+ EXPECT_EQ(eventReceiverAddressInfo, reteventReceiverAddressInfo);
}
TEST(SetEventReceiver, testBadDecodeRequest)
@@ -3712,6 +3723,22 @@
&rettransportProtocolType, &reteventReceiverAddressInfo,
&retheartbeatTimer);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ req->event_message_global_enable = PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC;
+ rc = decode_set_event_receiver_req(
+ request, PLDM_SET_EVENT_RECEIVER_MIN_REQ_BYTES - 1,
+ &reteventMessageGlobalEnable, &rettransportProtocolType,
+ &reteventReceiverAddressInfo, &retheartbeatTimer);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ req->event_message_global_enable =
+ PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
+ req->heartbeat_timer = 0;
+ rc = decode_set_event_receiver_req(
+ request, PLDM_SET_EVENT_RECEIVER_REQ_BYTES,
+ &reteventMessageGlobalEnable, &rettransportProtocolType,
+ &reteventReceiverAddressInfo, &retheartbeatTimer);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
}
TEST(decodeNumericSensorPdrData, Uint8Test)