tests: oem: meta: Fix fileio use of msgbuf
After resolving some undefined behavior regarding pointer arithmetic in
pldm_msgbuf_init(), clang-tidy detected the following:
```
clang-tidy-17 -export-fixes /tmp/tmpmu0oifam/tmpwpj83pgb.yaml -p=/home/andrew/src/openbmc.org/openbmc/libpldm/origin/buildkcgocca3 -quiet /home/andrew/src/openbmc.org/openbmc/libpldm/origin/tests/oem/meta/libpldm_fileio_test.cpp
../src/msgbuf.h:593:14: error: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch,-warnings-as-errors]
593 | if (!ctx || !ctx->cursor) {
| ^
../tests/oem/meta/libpldm_fileio_test.cpp:26:5: note: Calling 'pldm_msgbuf_init'
26 | pldm_msgbuf_init(ctx, 0, &buf[hdrSize], sizeof(buf) - hdrSize);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/msgbuf.h:75:7: note: 'ctx' is non-null
75 | if (!ctx || !buf) {
| ^~~
../src/msgbuf.h:75:6: note: Left side of '||' is false
75 | if (!ctx || !buf) {
| ^
../src/msgbuf.h:75:15: note: 'buf' is non-null
75 | if (!ctx || !buf) {
| ^~~
../src/msgbuf.h:75:2: note: Taking false branch
75 | if (!ctx || !buf) {
| ^
../src/msgbuf.h:79:7: note: 'minsize' is <= 'len'
79 | if ((minsize > len) || (len > SSIZE_MAX)) {
| ^~~~~~~
../src/msgbuf.h:79:6: note: Left side of '||' is false
79 | if ((minsize > len) || (len > SSIZE_MAX)) {
| ^
../src/msgbuf.h:79:26: note: 'len' is <= SSIZE_MAX
79 | if ((minsize > len) || (len > SSIZE_MAX)) {
| ^~~
../src/msgbuf.h:79:2: note: Taking false branch
79 | if ((minsize > len) || (len > SSIZE_MAX)) {
| ^
../src/msgbuf.h:83:6: note: Assuming the condition is true
83 | if ((uintptr_t)buf + len < len) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../src/msgbuf.h:83:2: note: Taking true branch
83 | if ((uintptr_t)buf + len < len) {
| ^
../src/msgbuf.h:84:3: note: Returning without writing to 'ctx->cursor'
84 | return PLDM_ERROR_INVALID_LENGTH;
| ^
../tests/oem/meta/libpldm_fileio_test.cpp:26:5: note: Returning from 'pldm_msgbuf_init'
26 | pldm_msgbuf_init(ctx, 0, &buf[hdrSize], sizeof(buf) - hdrSize);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/oem/meta/libpldm_fileio_test.cpp:28:5: note: Calling 'pldm_msgbuf_insert_uint8'
28 | pldm_msgbuf_insert_uint8(ctx, fileHandle);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/msgbuf.h:593:7: note: 'ctx' is non-null
593 | if (!ctx || !ctx->cursor) {
| ^~~
../src/msgbuf.h:593:6: note: Left side of '||' is false
593 | if (!ctx || !ctx->cursor) {
| ^
../src/msgbuf.h:593:14: note: Branch condition evaluates to a garbage value
593 | if (!ctx || !ctx->cursor) {
| ^~~~~~~~~~~~
```
Fixes: 22fad3957d36 ("oem: meta: Add decode_oem_meta_file_io_req()")
Change-Id: I99f1d6f8c28a7e812b12f5ef60af5d0f0b0d1866
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/tests/oem/meta/libpldm_fileio_test.cpp b/tests/oem/meta/libpldm_fileio_test.cpp
index de4ba81..decaa43 100644
--- a/tests/oem/meta/libpldm_fileio_test.cpp
+++ b/tests/oem/meta/libpldm_fileio_test.cpp
@@ -23,7 +23,8 @@
uint8_t buf[hdrSize + sizeof(uint8_t) + sizeof(int32_t) +
(postCodeSize * sizeof(uint8_t))] = {};
- pldm_msgbuf_init(ctx, 0, &buf[hdrSize], sizeof(buf) - hdrSize);
+ ASSERT_EQ(pldm_msgbuf_init(ctx, 0, &buf[hdrSize], sizeof(buf) - hdrSize),
+ 0);
pldm_msgbuf_insert_uint8(ctx, fileHandle);
pldm_msgbuf_insert_int32(ctx, dataLengthLE);
@@ -89,4 +90,4 @@
&retFileDataCnt, retDataField.data());
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
\ No newline at end of file
+}