msgbuf: Harden pldm_msgbuf_{insert,extract}_array()
Review of some proposed APIs suggested that correct use of the
pldm_msgbuf_{insert,extract}_array() helpers was more difficult that it
should be. In the three-parameter form, it was too tempting to provide
the length to extract as parsed out of a PLDM message. The intended
use was that the length parameter represented the length of the
user-provided data buffer.
Instead, move to a four-parameter form, provide reasonable documentation
for how these APIs should be used, fix all the call-sites, and deprecate
some existing unsafe APIs.
Change-Id: If58e5574600e80b354f383554283c4eda5d7234c
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/tests/dsp/firmware_update.cpp b/tests/dsp/firmware_update.cpp
index 8e96708..e21daf0 100644
--- a/tests/dsp/firmware_update.cpp
+++ b/tests/dsp/firmware_update.cpp
@@ -1940,17 +1940,24 @@
pldm_msgbuf_insert_uint32(buf, comparisonStamp);
pldm_msgbuf_insert_uint8(buf, (uint8_t)PLDM_STR_TYPE_ASCII);
pldm_msgbuf_insert_uint8(buf, activeCompVerStrLen);
- pldm_msgbuf_insert_array_char(buf, release_date, sizeof(release_date));
+ rc = pldm_msgbuf_insert_array_char(buf, sizeof(release_date), release_date,
+ sizeof(release_date));
+ ASSERT_EQ(rc, 0);
pldm_msgbuf_insert_uint32(buf, comparisonStamp);
pldm_msgbuf_insert_uint8(buf, (uint8_t)PLDM_STR_TYPE_ASCII);
pldm_msgbuf_insert_uint8(buf, pendingCompVerStrLen);
- pldm_msgbuf_insert_array_char(buf, release_date, sizeof(release_date));
+ rc = pldm_msgbuf_insert_array_char(buf, sizeof(release_date), release_date,
+ sizeof(release_date));
+ ASSERT_EQ(rc, 0);
pldm_msgbuf_insert_uint16(buf, compActivationMethods);
pldm_msgbuf_insert_uint32(buf, capabilitiesDuringUpdate);
- pldm_msgbuf_insert_array_char(buf, activeCompVerStr,
- sizeof(activeCompVerStr));
- pldm_msgbuf_insert_array_char(buf, pendingCompVerStr,
- sizeof(pendingCompVerStr));
+ rc = pldm_msgbuf_insert_array_char(
+ buf, activeCompVerStrLen, activeCompVerStr, sizeof(activeCompVerStr));
+ ASSERT_EQ(rc, 0);
+ rc = pldm_msgbuf_insert_array_char(buf, pendingCompVerStrLen,
+ pendingCompVerStr,
+ sizeof(pendingCompVerStr));
+ ASSERT_EQ(rc, 0);
variable_field rawData = {.ptr = responseMsg.data(),
.length = responseMsg.size()};
diff --git a/tests/dsp/platform.cpp b/tests/dsp/platform.cpp
index b121399..980cf5f 100644
--- a/tests/dsp/platform.cpp
+++ b/tests/dsp/platform.cpp
@@ -388,6 +388,81 @@
EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
}
+#ifdef LIBPLDM_API_TESTING
+TEST(GetPDR, testGoodDecodeResponseSafe)
+{
+ static const char recordData[] = "123456789";
+
+ alignas(pldm_msg) unsigned char data[sizeof(pldm_msg_hdr) +
+ PLDM_GET_PDR_MIN_RESP_BYTES +
+ sizeof(recordData) - 1 + 1];
+ struct pldm_msgbuf _buf;
+ struct pldm_msgbuf* buf = &_buf;
+ int rc;
+
+ pldm_msg* msg = new (data) pldm_msg;
+
+ rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_MIN_RESP_BYTES, msg->payload,
+ sizeof(data) - sizeof(msg->hdr));
+ ASSERT_EQ(rc, 0);
+
+ pldm_msgbuf_insert_uint8(buf, PLDM_SUCCESS);
+ pldm_msgbuf_insert_uint32(buf, 0);
+ pldm_msgbuf_insert_uint32(buf, 0);
+ pldm_msgbuf_insert_uint8(buf, PLDM_END);
+ pldm_msgbuf_insert_uint16(buf, sizeof(recordData) - 1);
+ rc = pldm_msgbuf_insert_array_char(buf, sizeof(recordData) - 1, recordData,
+ sizeof(recordData) - 1);
+ ASSERT_EQ(rc, 0);
+ pldm_msgbuf_insert_uint8(buf, 96);
+ ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
+
+ alignas(pldm_get_pdr_resp) unsigned char
+ resp_data[sizeof(pldm_get_pdr_resp) + sizeof(recordData) - 1];
+ pldm_get_pdr_resp* resp = new (resp_data) pldm_get_pdr_resp;
+ uint8_t crc;
+ rc = decode_get_pdr_resp_safe(msg, sizeof(data) - sizeof(msg->hdr), resp,
+ sizeof(resp_data) - sizeof(*resp), &crc);
+ ASSERT_EQ(rc, 0);
+ EXPECT_EQ(resp->completion_code, PLDM_SUCCESS);
+ EXPECT_EQ(resp->next_record_handle, 0);
+ EXPECT_EQ(resp->next_data_transfer_handle, 0);
+ EXPECT_EQ(resp->transfer_flag, PLDM_END);
+ ASSERT_EQ(resp->response_count, sizeof(recordData) - 1);
+ EXPECT_EQ(crc, 96);
+ EXPECT_EQ(0, memcmp(recordData, resp->record_data, resp->response_count));
+}
+#endif
+
+#ifdef LIBPLDM_API_TESTING
+TEST(GetPDR, testBadDecodeResponseSafeTrivial)
+{
+ pldm_get_pdr_resp resp;
+ uint8_t crc;
+ int rc;
+
+ rc = decode_get_pdr_resp_safe(nullptr, PLDM_GET_PDR_MIN_RESP_BYTES, &resp,
+ sizeof(resp), &crc);
+ EXPECT_EQ(rc, -EINVAL);
+
+ alignas(pldm_msg) unsigned char
+ msg_data[sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES];
+ pldm_msg* msg = new (msg_data) pldm_msg;
+ rc = decode_get_pdr_resp_safe(msg, PLDM_GET_PDR_MIN_RESP_BYTES, nullptr,
+ sizeof(resp), &crc);
+ EXPECT_EQ(rc, -EINVAL);
+
+ rc = decode_get_pdr_resp_safe(msg, PLDM_GET_PDR_MIN_RESP_BYTES, &resp,
+ sizeof(resp), nullptr);
+ EXPECT_EQ(rc, -EINVAL);
+
+ msg->payload[0] = PLDM_ERROR_INVALID_DATA;
+ rc = decode_get_pdr_resp_safe(msg, 1, &resp, sizeof(resp), &crc);
+ EXPECT_EQ(rc, 0);
+ EXPECT_EQ(resp.completion_code, PLDM_ERROR_INVALID_DATA);
+}
+#endif
+
TEST(GetPDRRepositoryInfo, testGoodEncodeResponse)
{
uint8_t completionCode = 0;
@@ -550,6 +625,82 @@
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
}
+#ifdef LIBPLDM_API_TESTING
+TEST(GetPDRRepositoryInfo, testGoodDecodeResponseSafe)
+{
+ alignas(pldm_msg) unsigned char
+ data[sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES];
+ uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
+ uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
+ struct pldm_msgbuf _buf;
+ struct pldm_msgbuf* buf = &_buf;
+ int rc;
+
+ pldm_msg* msg = new (data) pldm_msg;
+
+ rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
+ msg->payload, sizeof(data) - sizeof(msg->hdr));
+ ASSERT_EQ(rc, 0);
+ pldm_msgbuf_insert_uint8(buf, PLDM_SUCCESS);
+ pldm_msgbuf_insert_uint8(buf, PLDM_AVAILABLE);
+ rc = pldm_msgbuf_insert_array_uint8(buf, PLDM_TIMESTAMP104_SIZE, updateTime,
+ sizeof(updateTime));
+ ASSERT_EQ(rc, 0);
+ rc = pldm_msgbuf_insert_array_uint8(buf, PLDM_TIMESTAMP104_SIZE,
+ oemUpdateTime, sizeof(oemUpdateTime));
+ ASSERT_EQ(rc, 0);
+ pldm_msgbuf_insert_uint32(buf, 100);
+ pldm_msgbuf_insert_uint32(buf, 100);
+ pldm_msgbuf_insert_uint32(buf, UINT32_MAX);
+ pldm_msgbuf_insert_uint8(buf, PLDM_NO_TIMEOUT);
+ ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
+
+ struct pldm_pdr_repository_info_resp resp;
+ rc = decode_get_pdr_repository_info_resp_safe(
+ msg, sizeof(data) - sizeof(msg->hdr), &resp);
+
+ EXPECT_EQ(rc, 0);
+ EXPECT_EQ(PLDM_SUCCESS, resp.completion_code);
+ EXPECT_EQ(PLDM_AVAILABLE, resp.repository_state);
+ EXPECT_EQ(0,
+ memcmp(updateTime, resp.update_time, sizeof(resp.update_time)));
+ EXPECT_EQ(0, memcmp(oemUpdateTime, resp.oem_update_time,
+ sizeof(resp.oem_update_time)));
+ EXPECT_EQ(100, resp.record_count);
+ EXPECT_EQ(100, resp.repository_size);
+ EXPECT_EQ(UINT32_MAX, resp.largest_record_size);
+ EXPECT_EQ(PLDM_NO_TIMEOUT, resp.data_transfer_handle_timeout);
+}
+#endif
+
+#ifdef LIBPLDM_API_TESTING
+TEST(GetPDRRepositoryInfo, testBadDecodeResponseSafeTrivial)
+{
+ struct pldm_pdr_repository_info_resp resp;
+ int rc;
+
+ rc = decode_get_pdr_repository_info_resp_safe(
+ nullptr, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES, &resp);
+ EXPECT_EQ(rc, -EINVAL);
+
+ alignas(pldm_msg) unsigned char
+ msg_data[sizeof(pldm_msg) - 1 +
+ PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES];
+ pldm_msg* msg = new (msg_data) pldm_msg;
+ rc = decode_get_pdr_repository_info_resp_safe(msg, 0, &resp);
+ EXPECT_EQ(rc, -EOVERFLOW);
+
+ rc = decode_get_pdr_repository_info_resp_safe(
+ msg, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES, nullptr);
+ EXPECT_EQ(rc, -EINVAL);
+
+ msg->payload[0] = PLDM_ERROR_INVALID_DATA;
+ rc = decode_get_pdr_repository_info_resp_safe(msg, 1, &resp);
+ EXPECT_EQ(rc, 0);
+ EXPECT_EQ(resp.completion_code, PLDM_ERROR_INVALID_DATA);
+}
+#endif
+
TEST(SetNumericEffecterValue, testGoodDecodeRequest)
{
std::array<uint8_t,
@@ -1659,7 +1810,9 @@
pldm_msgbuf_extract_uint8(buf, &retTransferFlag);
pldm_msgbuf_extract_uint8(buf, &retEventClass);
pldm_msgbuf_extract_uint32(buf, &retEventDataSize);
- pldm_msgbuf_extract_array_uint8(buf, retEventData, retEventDataSize);
+ rc = pldm_msgbuf_extract_array_uint8(buf, retEventDataSize, retEventData,
+ sizeof(retEventData));
+ ASSERT_EQ(rc, 0);
pldm_msgbuf_extract_uint32(buf, &retEventDataIntegrityChecksum);
EXPECT_EQ(rc, PLDM_SUCCESS);
@@ -5267,7 +5420,7 @@
rc = decode_pldm_platform_cper_event(
reinterpret_cast<uint8_t*>(eventData.data()), eventData.size() - 1,
cperEvent, cperEventSize);
- EXPECT_EQ(rc, -EBADMSG);
+ EXPECT_EQ(rc, -EOVERFLOW);
#else
EXPECT_DEATH(decode_pldm_platform_cper_event(
reinterpret_cast<uint8_t*>(eventData.data()),
diff --git a/tests/msgbuf.cpp b/tests/msgbuf.cpp
index c84acce..e7f9e62 100644
--- a/tests/msgbuf.cpp
+++ b/tests/msgbuf.cpp
@@ -413,7 +413,7 @@
uint8_t arr[1];
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_extract_array_uint8(ctx, arr, 0), PLDM_SUCCESS);
+ EXPECT_EQ(pldm_msgbuf_extract_array_uint8(ctx, 0, arr, 0), PLDM_SUCCESS);
ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
}
@@ -425,8 +425,9 @@
uint8_t arr[1];
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_extract_array_uint8(ctx, arr, sizeof(arr)),
- PLDM_SUCCESS);
+ EXPECT_EQ(
+ pldm_msgbuf_extract_array_uint8(ctx, sizeof(arr), arr, sizeof(arr)),
+ PLDM_SUCCESS);
EXPECT_EQ(arr[0], 0);
ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
}
@@ -439,8 +440,9 @@
uint8_t arr[2];
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_NE(pldm_msgbuf_extract_array_uint8(ctx, arr, sizeof(arr)),
- PLDM_SUCCESS);
+ EXPECT_NE(
+ pldm_msgbuf_extract_array_uint8(ctx, sizeof(arr), arr, sizeof(arr)),
+ PLDM_SUCCESS);
ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
}
@@ -453,7 +455,7 @@
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
ctx->remaining = INTMAX_MIN;
- EXPECT_NE(pldm_msgbuf_extract_array_uint8(ctx, arr, 1), PLDM_SUCCESS);
+ EXPECT_NE(pldm_msgbuf_extract_array_uint8(ctx, 1, arr, 1), PLDM_SUCCESS);
ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
}
@@ -465,7 +467,7 @@
char arr[1] = {'1'};
ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
- EXPECT_EQ(pldm_msgbuf_extract_array_char(ctx, arr, 0), 0);
+ EXPECT_EQ(pldm_msgbuf_extract_array_char(ctx, 0, arr, 0), 0);
ASSERT_EQ(pldm_msgbuf_destroy(ctx), 0);
}
@@ -477,7 +479,8 @@
char arr[1] = {'1'};
ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
- EXPECT_EQ(pldm_msgbuf_extract_array_char(ctx, arr, sizeof(arr)), 0);
+ EXPECT_EQ(
+ pldm_msgbuf_extract_array_char(ctx, sizeof(arr), arr, sizeof(arr)), 0);
EXPECT_EQ(arr[0], '\0');
ASSERT_EQ(pldm_msgbuf_destroy(ctx), 0);
}
@@ -490,7 +493,8 @@
char arr[2] = {'1', '2'};
ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
- EXPECT_NE(pldm_msgbuf_extract_array_char(ctx, arr, sizeof(arr)), 0);
+ EXPECT_NE(
+ pldm_msgbuf_extract_array_char(ctx, sizeof(arr), arr, sizeof(arr)), 0);
ASSERT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
}
@@ -503,7 +507,7 @@
ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
ctx->remaining = INTMAX_MIN;
- EXPECT_NE(pldm_msgbuf_extract_array_char(ctx, arr, 1), 0);
+ EXPECT_NE(pldm_msgbuf_extract_array_char(ctx, 1, arr, 1), 0);
ASSERT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
}
@@ -773,17 +777,18 @@
uint8_t retBuff[6] = {};
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_insert_array_uint8(ctx, src, sizeof(src)),
- PLDM_SUCCESS);
+ EXPECT_EQ(
+ pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
+ PLDM_SUCCESS);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
PLDM_SUCCESS);
- EXPECT_EQ(
- pldm_msgbuf_extract_array_uint8(ctxExtract, retBuff, sizeof(retBuff)),
- PLDM_SUCCESS);
+ EXPECT_EQ(pldm_msgbuf_extract_array_uint8(ctxExtract, sizeof(retBuff),
+ retBuff, sizeof(retBuff)),
+ PLDM_SUCCESS);
EXPECT_EQ(memcmp(src, retBuff, sizeof(retBuff)), 0);
EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
@@ -798,8 +803,9 @@
uint8_t buf[6] = {};
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_insert_array_uint8(ctx, NULL, sizeof(src)),
- PLDM_ERROR_INVALID_DATA);
+ EXPECT_EQ(
+ pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), NULL, sizeof(src)),
+ PLDM_ERROR_INVALID_DATA);
EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
}
@@ -813,8 +819,9 @@
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
- EXPECT_NE(pldm_msgbuf_insert_array_uint8(ctx, val, sizeof(val)),
- PLDM_SUCCESS);
+ EXPECT_NE(
+ pldm_msgbuf_insert_array_uint8(ctx, sizeof(val), val, sizeof(val)),
+ PLDM_SUCCESS);
EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
}
@@ -827,15 +834,16 @@
char retBuff[6] = {};
ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
- EXPECT_EQ(pldm_msgbuf_insert_array_char(ctx, src, sizeof(src)), 0);
+ EXPECT_EQ(pldm_msgbuf_insert_array_char(ctx, sizeof(src), src, sizeof(src)),
+ 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
- EXPECT_EQ(
- pldm_msgbuf_extract_array_char(ctxExtract, retBuff, sizeof(retBuff)),
- 0);
+ EXPECT_EQ(pldm_msgbuf_extract_array_char(ctxExtract, sizeof(retBuff),
+ retBuff, sizeof(retBuff)),
+ 0);
EXPECT_EQ(memcmp(src, retBuff, sizeof(retBuff)), 0);
EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
@@ -850,7 +858,9 @@
char buf[6] = {};
ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
- EXPECT_EQ(pldm_msgbuf_insert_array_char(ctx, NULL, sizeof(src)), -EINVAL);
+ EXPECT_EQ(
+ pldm_msgbuf_insert_array_char(ctx, sizeof(src), NULL, sizeof(src)),
+ -EINVAL);
EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
}
@@ -863,7 +873,8 @@
ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
- EXPECT_NE(pldm_msgbuf_insert_array_char(ctx, val, sizeof(val)), 0);
+ EXPECT_NE(pldm_msgbuf_insert_array_char(ctx, sizeof(val), val, sizeof(val)),
+ 0);
EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
}
@@ -879,8 +890,9 @@
uint8_t* retBuff = NULL;
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_insert_array_uint8(ctx, src, sizeof(src)),
- PLDM_SUCCESS);
+ EXPECT_EQ(
+ pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
+ PLDM_SUCCESS);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
@@ -907,8 +919,9 @@
[[maybe_unused]] uint8_t* retBuff = NULL;
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_insert_array_uint8(ctx, src, sizeof(src)),
- PLDM_SUCCESS);
+ EXPECT_EQ(
+ pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
+ PLDM_SUCCESS);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
@@ -1264,8 +1277,9 @@
uint8_t* retBuff = NULL;
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_insert_array_uint8(ctx, src, sizeof(src)),
- PLDM_SUCCESS);
+ EXPECT_EQ(
+ pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
+ PLDM_SUCCESS);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
@@ -1294,8 +1308,9 @@
uint8_t* retBuff = NULL;
ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
- EXPECT_EQ(pldm_msgbuf_insert_array_uint8(ctx, src, sizeof(src)),
- PLDM_SUCCESS);
+ EXPECT_EQ(
+ pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
+ PLDM_SUCCESS);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
diff --git a/tests/msgbuf_generic.c b/tests/msgbuf_generic.c
index 96b3bb5..32b9ed9 100644
--- a/tests/msgbuf_generic.c
+++ b/tests/msgbuf_generic.c
@@ -139,7 +139,7 @@
expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
PLDM_SUCCESS);
- expect(pldm_msgbuf_extract_array(ctx, arr, 1) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_extract_array(ctx, 1, arr, 1) == PLDM_SUCCESS);
expect(arr[0] == 0);
expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
}
@@ -291,15 +291,16 @@
uint8_t retBuff[6] = {0};
expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert_array(ctx, src, sizeof(src)) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_insert_array(ctx, sizeof(src), src, sizeof(src)) ==
+ PLDM_SUCCESS);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
PLDM_SUCCESS);
- expect(pldm_msgbuf_extract_array(ctxExtract, retBuff, sizeof(retBuff)) ==
- PLDM_SUCCESS);
+ expect(pldm_msgbuf_extract_array(ctxExtract, sizeof(retBuff), retBuff,
+ sizeof(retBuff)) == PLDM_SUCCESS);
expect(memcmp(src, retBuff, sizeof(retBuff)) == 0);
expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
diff --git a/tests/oem/meta/fileio.cpp b/tests/oem/meta/fileio.cpp
index da38679..1f11fc5 100644
--- a/tests/oem/meta/fileio.cpp
+++ b/tests/oem/meta/fileio.cpp
@@ -17,6 +17,7 @@
uint8_t fileHandle = 0x00;
int32_t dataLengthLE = 0x04;
uint8_t postCode[4] = {0x93, 0xe0, 0x00, 0xea};
+ int rc;
constexpr auto hdrSize = sizeof(pldm_msg_hdr);
@@ -28,7 +29,9 @@
pldm_msgbuf_insert_uint8(ctx, fileHandle);
pldm_msgbuf_insert_int32(ctx, dataLengthLE);
- pldm_msgbuf_insert_array_uint8(ctx, postCode, sizeof(postCode));
+ rc = pldm_msgbuf_insert_array_uint8(ctx, sizeof(postCode), postCode,
+ sizeof(postCode));
+ ASSERT_EQ(rc, PLDM_SUCCESS);
std::array<uint8_t, oemMetaDecodeWriteFileIoReqBytes> retDataField{};
@@ -37,11 +40,11 @@
auto request = reinterpret_cast<pldm_msg*>(buf);
- auto rc = decode_oem_meta_file_io_req(request, sizeof(buf) - hdrSize,
- &retfileHandle, &retFileDataCnt,
- retDataField.data());
+ rc = decode_oem_meta_file_io_req(request, sizeof(buf) - hdrSize,
+ &retfileHandle, &retFileDataCnt,
+ retDataField.data());
- EXPECT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(rc, PLDM_SUCCESS);
EXPECT_EQ(retfileHandle, fileHandle);
EXPECT_EQ(retFileDataCnt, dataLengthLE);
EXPECT_EQ(retDataField[0], postCode[0]);