[Skiboot] [PATCH] ipmi/fru: Remove redundant version information

alistair at popple.id.au alistair at popple.id.au
Wed Dec 3 13:35:58 AEDT 2014


From: Alistair Popple <alistair at popple.id.au>

The FRU data format limits string length to 31 characters. Currently
we truncate the version string as required but leave the redundant
(because it's included in the product name field) "skiboot-" at the
start of the version.

This patch removes the redundant prefix allowing more of the actual
version string to be stored. It also fixes a bug which caused the last
character of a 31 character version string to be overwritten as well
as a rather embarrassing off-by-one buffer overflow.

Note that 31 characters should be enough to store the complete version
string for any release builds.

Signed-off-by: Alistair Popple <alistair at popple.id.au>
---
 hw/ipmi/ipmi-fru.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/ipmi/ipmi-fru.c b/hw/ipmi/ipmi-fru.c
index 3c8ea03..49a7e0f 100644
--- a/hw/ipmi/ipmi-fru.c
+++ b/hw/ipmi/ipmi-fru.c
@@ -127,7 +127,7 @@ static int fru_fill_product_info(u8 *buf, struct product_info *info, size_t size
 static int fru_add(u8 *buf, int size)
 {
 	int len;
-	char short_version[MAX_STR_LEN];
+	char short_version[MAX_STR_LEN + 1];
 	struct common_header common_hdr;
 	struct product_info info = {
 		.manufacturer = (char *) "IBM",
@@ -154,10 +154,14 @@ static int fru_add(u8 *buf, int size)
 	memcpy(buf, &common_hdr, sizeof(common_hdr));
 
 	info.version = short_version;
-	strncpy(info.version, version, MAX_STR_LEN);
-	info.version[MAX_STR_LEN] = '\0';
-	if (info.version[MAX_STR_LEN - 1] != '\0')
+	if (!strncmp(version, "skiboot-", 8))
+		strncpy(info.version, &version[8], MAX_STR_LEN + 1);
+	else
+		strncpy(info.version, version, MAX_STR_LEN + 1);
+
+	if (info.version[MAX_STR_LEN] != '\0')
 		info.version[MAX_STR_LEN - 1] = '+';
+	info.version[MAX_STR_LEN] = '\0';
 
 	len = fru_fill_product_info(&buf[64], &info, size - 64);
 	if (len < 0)
-- 
1.8.3.2



More information about the Skiboot mailing list