diff options
author | Alistair Popple <alistair@popple.id.au> | 2014-12-03 13:35:58 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2014-12-03 17:13:08 +1100 |
commit | 1374d4436117423015704dedf1986c6a3314bc3a (patch) | |
tree | 88753e50d869688633b3f762f2dcac9dc2a2e052 /hw/ipmi | |
parent | af3569322c99d7900b7bbb385e160829ef4275db (diff) | |
download | skiboot-1374d4436117423015704dedf1986c6a3314bc3a.zip skiboot-1374d4436117423015704dedf1986c6a3314bc3a.tar.gz skiboot-1374d4436117423015704dedf1986c6a3314bc3a.tar.bz2 |
ipmi/fru: Remove redundant version information
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@popple.id.au>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'hw/ipmi')
-rw-r--r-- | hw/ipmi/ipmi-fru.c | 12 |
1 files 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) |