pldm: Migrate off deprecated libpldm BIOS table entry encoding APIs
libpldm has deprecated the affected APIs. Prefer using their `*_check()`
variants as these return an error code rather than prevent misbehaviour
with assert().
1. pldm_bios_table_attr_entry_integer_encode()
2. pldm_bios_table_attr_value_entry_encode_enum()
3. pldm_bios_table_attr_value_entry_encode_string()
4. pldm_bios_table_attr_value_entry_encode_integer()
Tested: Successfully booted a p10bmc host, dumped each of the BIOS
tables with pldmtool without issue
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I823b24884e518f8c53fd153b3bc30569595ecd86
diff --git a/libpldmresponder/bios_table.cpp b/libpldmresponder/bios_table.cpp
index 898a34a..f29d813 100644
--- a/libpldmresponder/bios_table.cpp
+++ b/libpldmresponder/bios_table.cpp
@@ -161,7 +161,6 @@
"LIBPLDM_ERROR", rc);
throw std::runtime_error("Failed to encode BIOS table string entry");
}
-
return reinterpret_cast<pldm_bios_attr_table_entry*>(table.data() +
tableSize);
}
@@ -173,8 +172,16 @@
auto entryLength = pldm_bios_table_attr_entry_integer_encode_length();
auto tableSize = table.size();
table.resize(tableSize + entryLength, 0);
- pldm_bios_table_attr_entry_integer_encode(table.data() + tableSize,
- entryLength, info);
+ int rc = pldm_bios_table_attr_entry_integer_encode_check(
+ table.data() + tableSize, entryLength, info);
+ if (rc != PLDM_SUCCESS)
+ {
+ lg2::error(
+ "Failed to encode BIOS attribute table integer entry: {LIBPLDM_ERROR}",
+ "LIBPLDM_ERROR", rc);
+ throw std::runtime_error(
+ "Failed to encode BIOS attribute table integer entry");
+ }
return reinterpret_cast<pldm_bios_attr_table_entry*>(table.data() +
tableSize);
}
@@ -299,9 +306,17 @@
pldm_bios_table_attr_value_entry_encode_string_length(strLen);
auto tableSize = table.size();
table.resize(tableSize + entryLength);
- pldm_bios_table_attr_value_entry_encode_string(
+ int rc = pldm_bios_table_attr_value_entry_encode_string_check(
table.data() + tableSize, entryLength, attrHandle, attrType, strLen,
str.c_str());
+ if (rc != PLDM_SUCCESS)
+ {
+ lg2::error(
+ "Failed to encode BIOS attribute table string entry: {LIBPLDM_ERROR}",
+ "LIBPLDM_ERROR", rc);
+ throw std::runtime_error(
+ "Failed to encode BIOS attribute table string entry");
+ }
return reinterpret_cast<pldm_bios_attr_val_table_entry*>(table.data() +
tableSize);
}
@@ -329,9 +344,17 @@
handleIndices.size());
auto tableSize = table.size();
table.resize(tableSize + entryLength);
- pldm_bios_table_attr_value_entry_encode_enum(
+ int rc = pldm_bios_table_attr_value_entry_encode_enum_check(
table.data() + tableSize, entryLength, attrHandle, attrType,
handleIndices.size(), handleIndices.data());
+ if (rc != PLDM_SUCCESS)
+ {
+ lg2::error(
+ "Failed to encode BIOS attribute table enum entry: {LIBPLDM_ERROR}",
+ "LIBPLDM_ERROR", rc);
+ throw std::runtime_error(
+ "Failed to encode BIOS attribute table enum entry");
+ }
return reinterpret_cast<pldm_bios_attr_val_table_entry*>(table.data() +
tableSize);
}
diff --git a/pldmtool/pldm_bios_cmd.cpp b/pldmtool/pldm_bios_cmd.cpp
index 6cf3e37..f4c5ecc 100644
--- a/pldmtool/pldm_bios_cmd.cpp
+++ b/pldmtool/pldm_bios_cmd.cpp
@@ -862,9 +862,16 @@
attrValueEntry.resize(entryLength);
std::vector<uint8_t> handles = {i};
- pldm_bios_table_attr_value_entry_encode_enum(
+ int rc = pldm_bios_table_attr_value_entry_encode_enum_check(
attrValueEntry.data(), attrValueEntry.size(),
attrEntry->attr_handle, attrType, 1, handles.data());
+ if (rc != PLDM_SUCCESS)
+ {
+ std::cout
+ << "Failed to encode BIOS table attribute enum: " << rc
+ << std::endl;
+ return;
+ }
break;
}
case PLDM_BIOS_STRING:
@@ -876,9 +883,16 @@
attrValueEntry.resize(entryLength);
- pldm_bios_table_attr_value_entry_encode_string(
+ int rc = pldm_bios_table_attr_value_entry_encode_string_check(
attrValueEntry.data(), entryLength, attrEntry->attr_handle,
attrType, attrValue.size(), attrValue.c_str());
+ if (rc != PLDM_SUCCESS)
+ {
+ std::cout
+ << "Failed to encode BIOS table attribute string: "
+ << rc << std::endl;
+ return;
+ }
break;
}
case PLDM_BIOS_INTEGER: