From 3411537228b83ff9b9db22c416d464d83abff9a7 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 23 Oct 2015 15:45:50 -0400 Subject: [PATCH] Workaround likely spec deviations and fix parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For one, was doing UTF-8, though the encoding strictly speaking per speac should be ISO-8859-1. Corrected that mistake. Also workaround an issue when FRU may be programmed with 0x0 or 0xff bytes to terminate, or spaces. The spec actually doesn't speak to a strategy to pad strings (presumably because they assumed implementation would avail itself of the capacity for variable strings and not need to deal with silly fixed length fields). Handle this by trimming out trailing spaces, 0x0, or 0xff. This strictly speaking violates the spec if they want to use one or more ΓΏ to end a field, but will take the risk that no one actually would want to do that. Change-Id: I7d7e3aa9f3fd2b1e1af75f98cabd49ca374755c0 --- pyghmi/ipmi/fru.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pyghmi/ipmi/fru.py b/pyghmi/ipmi/fru.py index 2ed64f71..4995b894 100644 --- a/pyghmi/ipmi/fru.py +++ b/pyghmi/ipmi/fru.py @@ -214,9 +214,16 @@ class FRU(object): # return it as a bytearray, not much to be done for it return retinfo, newoffset elif currtype == 3: # text string - if lang == 0: + # Sometimes BMCs have FRU data with 0xff termination + # contrary to spec, but can be tolerated + # also in case something null terminates, handle that too + # strictly speaking, \xff should be a y with diaeresis, but + # erring on the side of that not being very relevant in practice + # to fru info, particularly the last values + retinfo = retinfo.rstrip('\xff\x00 ') + if lang in (0, 25): try: - retinfo = retinfo.decode('utf-8') + retinfo = retinfo.decode('iso-8859-1') except UnicodeDecodeError: pass else: