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/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) {