ipmi_fru_info_area: Pad output buffer.
Always pad the output buffer to the maximum IPMI FRU size. This enables
tools like ipmitool to write a new FRU blob with data longer than the
original payload.
Change-Id: Id6eb2c80504fb42ac72d7b643d186e9641a0832c
Signed-off-by: Oskar Senft <osk@google.com>
diff --git a/ipmi_fru_info_area.cpp b/ipmi_fru_info_area.cpp
index e10eee5..089a7cb 100644
--- a/ipmi_fru_info_area.cpp
+++ b/ipmi_fru_info_area.cpp
@@ -46,6 +46,16 @@
static constexpr auto secsToMaxMfgdate =
secs_from_1970_1996 + secs_per_min * maxMfgDateValue;
+// Minimum size of resulting FRU blob.
+// This is also the theoretical maximum size according to the spec:
+// 8 bytes header + 5 areas at 0xff*8 bytes max each
+// 8 + 5*0xff*8 = 0x27e0
+static constexpr auto fruMinSize = 0x27E0;
+
+// Value to use for padding.
+// Using 0xff to match the default (blank) value in a physical EEPROM.
+static constexpr auto fruPadValue = 0xff;
+
/**
* @brief Format Beginning of Individual IPMI FRU Data Section
*
@@ -427,6 +437,13 @@
// add product use area data
combFruArea.insert(combFruArea.end(), prodArea.begin(), prodArea.end());
+ // If area is smaller than the minimum size, pad it. This enables ipmitool
+ // to update the FRU blob with values longer than the original payload.
+ if (combFruArea.size() < fruMinSize)
+ {
+ combFruArea.resize(fruMinSize, fruPadValue);
+ }
+
return combFruArea;
}