| From 92388b2c470dd4b01bf47902132349319b8f0cd6 Mon Sep 17 00:00:00 2001 |
| From: Kasun Athukorala <kasunath@google.com> |
| Date: Fri, 5 Sep 2025 18:50:26 +0000 |
| Subject: [PATCH] dsp: base: Fix MultipartReceive Request decoding |
| |
| This fix is based on DSP0240 v1.2.0 section 9.6.5 MultipartReceive. |
| |
| - Removed RequestedSectionOffset check. |
| |
| The Property can be 0 for any TransferOperation flag. |
| |
| - Changed DataTransferHandle check. |
| |
| The property can be 0 except with PLDM_XFER_NEXT_PART. Eg. In |
| DSP0242 v1.0.0, when using MultipartReceive to read a file, |
| the client has to send transfer handle 0 with XFER_FIRST_PART. |
| |
| Change-Id: I06428556f9dee341de97f72b015ed0347adc9454 |
| Signed-off-by: Kasun Athukorala <kasunath@google.com> |
| --- |
| CHANGELOG.md | 4 ++++ |
| src/dsp/base.c | 11 ++++------- |
| tests/dsp/base.cpp | 37 ------------------------------------- |
| 3 files changed, 8 insertions(+), 44 deletions(-) |
| |
| diff --git a/CHANGELOG.md b/CHANGELOG.md |
| index 9f28c0d..b28a4fc 100644 |
| --- a/CHANGELOG.md |
| +++ b/CHANGELOG.md |
| @@ -96,6 +96,10 @@ Change categories: |
| - include, tests: Address concerns from -Wsign-compare |
| - dsp: base: decode_pldm_base_negotiate_transfer_params_resp() is stable |
| |
| +- base: |
| + - Removed RequestedSectionOffset check in decode_multipart_receive_req() |
| + - Updated DataTransferHandle check in decode_multipart_receive_req() |
| + |
| ### Security |
| |
| ## [0.14.0] 2025-08-11 |
| diff --git a/src/dsp/base.c b/src/dsp/base.c |
| index cc805df..eb0aaa4 100644 |
| --- a/src/dsp/base.c |
| +++ b/src/dsp/base.c |
| @@ -569,13 +569,10 @@ int decode_multipart_receive_req(const struct pldm_msg *msg, |
| return PLDM_ERROR_UNEXPECTED_TRANSFER_FLAG_OPERATION; |
| } |
| |
| - // A section offset of 0 is only valid on FIRST_PART or COMPLETE Xfers. |
| - if (*section_offset == 0 && (*transfer_opflag != PLDM_XFER_FIRST_PART && |
| - *transfer_opflag != PLDM_XFER_COMPLETE)) { |
| - return PLDM_ERROR_INVALID_DATA; |
| - } |
| - |
| - if (*transfer_handle == 0 && *transfer_opflag != PLDM_XFER_COMPLETE) { |
| + // Transfer handle can be 0 only if the transfer flag is one of XFER_FIRST_PART, |
| + // PLDM_XFER_CURRENT_PART, XFER_ABORT or XFER_COMPLETE. |
| + if ((*transfer_handle == 0) && |
| + (*transfer_opflag == PLDM_XFER_NEXT_PART)) { |
| return PLDM_ERROR_INVALID_DATA; |
| } |
| |
| diff --git a/tests/dsp/base.cpp b/tests/dsp/base.cpp |
| index f146e7c..b2e9294 100644 |
| --- a/tests/dsp/base.cpp |
| +++ b/tests/dsp/base.cpp |
| @@ -674,43 +674,6 @@ TEST(DecodeMultipartReceiveRequest, testDecodeRequestFailBadTransferFlag) |
| PLDM_ERROR_UNEXPECTED_TRANSFER_FLAG_OPERATION); |
| } |
| |
| -TEST(DecodeMultipartReceiveRequest, testDecodeRequestFailBadOffset) |
| -{ |
| - constexpr uint8_t kPldmType = PLDM_BASE; |
| - constexpr uint8_t kFlag = PLDM_XFER_NEXT_PART; |
| - constexpr uint32_t kTransferCtx = 0x01; |
| - constexpr uint32_t kTransferHandle = 0x01; |
| - constexpr uint32_t kSectionOffset = 0x0; |
| - |
| - PLDM_MSG_DEFINE_P(msg, PLDM_MULTIPART_RECEIVE_REQ_BYTES); |
| - PLDM_MSGBUF_RW_DEFINE_P(buf); |
| - int rc; |
| - |
| - // Header values don't matter for this test. |
| - rc = pldm_msgbuf_init_errno(buf, PLDM_MULTIPART_RECEIVE_REQ_BYTES, |
| - msg->payload, PLDM_MULTIPART_RECEIVE_REQ_BYTES); |
| - ASSERT_EQ(rc, 0); |
| - pldm_msgbuf_insert_uint8(buf, kPldmType); |
| - pldm_msgbuf_insert_uint8(buf, kFlag); |
| - pldm_msgbuf_insert_uint32(buf, kTransferCtx); |
| - pldm_msgbuf_insert_uint32(buf, kTransferHandle); |
| - pldm_msgbuf_insert_uint32(buf, kSectionOffset); |
| - rc = pldm_msgbuf_complete(buf); |
| - ASSERT_EQ(rc, 0); |
| - |
| - uint8_t pldm_type; |
| - uint8_t flag; |
| - uint32_t transfer_ctx; |
| - uint32_t transfer_handle; |
| - uint32_t section_offset; |
| - uint32_t section_length; |
| - EXPECT_EQ(decode_multipart_receive_req( |
| - msg, PLDM_MULTIPART_RECEIVE_REQ_BYTES, &pldm_type, &flag, |
| - &transfer_ctx, &transfer_handle, §ion_offset, |
| - §ion_length), |
| - PLDM_ERROR_INVALID_DATA); |
| -} |
| - |
| TEST(DecodeMultipartReceiveRequest, testDecodeRequestFailBadHandle) |
| { |
| constexpr uint8_t kPldmType = PLDM_BASE; |
| -- |
| 2.51.0.536.g15c5d4f767-goog |
| |