[PATCH phosphor-host-ipmid v3] ipmid crashing with simplified VERSION_ID

OpenBMC Patches openbmc-patches at stwcx.xyz
Tue May 3 10:30:42 AEST 2016


From: Chris Austen <austenc at us.ibm.com>

if the VERSION_ID is v0.1 instead of v0.1-1 then the code will crash.  The fix is to always check
for a NULL token each time.

Change ipmitool output to reflect hex value

VERSION_ID is equal to v0.6-36-gece9f78-dirty
I was forcing the '36' to be shown as 36.  Turns out
that the ipmitool prepends the "Aux" section with a
'0x' indicating the value is in hex.  So Rather then
it show up as 0x36  I made it actually be 0x24.

root at barreleye:~# ./ipmitool -I dbus mc info
IPMI GROUP EXTENTIONS
IPMI GROUP EXTENTIONS
Device ID                 : 0
Device Revision           : 0
Firmware Revision         : 0.06
IPMI Version              : 2.0
Manufacturer ID           : 42817
Manufacturer Name         : Unknown (0xA741)
Product ID                : 16451 (0x4043)
Product Name              : Unknown (0x4043)
Device Available          : yes
Provides Device SDRs      : no
Additional Device Support :
    Sensor Device
    SEL Device
    FRU Inventory Device
Aux Firmware Rev Info     :
    0x00
    0x24   <---- is decimal 36
    0x01
    0x00
root at barreleye:~#
---
 apphandler.C | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/apphandler.C b/apphandler.C
index 53a83d3..71dba66 100644
--- a/apphandler.C
+++ b/apphandler.C
@@ -100,7 +100,7 @@ typedef struct
 {
     char major;
     char minor;
-    uint8_t d[4];
+    uint16_t d[2];
 } rev_t;
 
 
@@ -119,6 +119,7 @@ int convert_version(const char *p, rev_t *rev)
     char *s, *token;
     char hexbyte[5];
     int l;
+    uint16_t commits;
 
     if (*p != 'v')
         return -1;
@@ -135,23 +136,23 @@ int convert_version(const char *p, rev_t *rev)
     // Capture the number of commits on top of the minor tag.
     // I'm using BE format like the ipmi spec asked for
     token = strtok(NULL,".-");
-    l = strlen(token);
-    if (l > 4)
-        l = 4;
 
-    memset(hexbyte,'0', 4);
-    memcpy(&hexbyte[4-l], token, l);
-    sscanf(&hexbyte[0], "%2hhX", &rev->d[0]);
-    sscanf(&hexbyte[2], "%2hhX", &rev->d[1]);
+    if (token) {
+        commits = (int16_t) atoi(token);
+        rev->d[0] = (commits>>8) | (commits<<8);
 
-    rev->d[2] = 0;
+        // commit number we skip
+        token = strtok(NULL,".-");
 
-    // commit number we skip
-    token = strtok(NULL,".-");
+    } else {
+        rev->d[0] = 0;
+    }
 
     // Any value of the optional parameter forces it to 1
-    token = strtok(NULL,".-");
-        rev->d[3] = (token != NULL) ? 1 : 0;
+    if (token)
+        token = strtok(NULL,".-");
+
+    rev->d[1] = (token != NULL) ? 1 : 0;
 
     free(s);
     return 0;
-- 
2.8.1




More information about the openbmc mailing list