From 5bb4540dbbb5bf85121dee4dfd9e1b982bcac953 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 18 Jul 2024 09:39:05 +0200 Subject: [PATCH] virsysinfo: Be more forgiving when decoding OEM strings On some systems, there are two or even more 'OEM Strings' sections in DMI table. Here's an example of dmidecode output on such system: # dmidecode -q -t 11 OEM Strings String 1: Default string OEM Strings String 1: ThunderX2 System String 2: cavium.com String 3: Comanche Now, this poses a problem, because when one tries to obtain individual strings, they get: # dmidecode -q --oem-string 1 Default string ThunderX2 System # dmidecode -q --oem-string 2 No OEM string number 2 cavium.com NB, the "No OEM string number 2" is printed onto stderr and everything else onto stdout. Oh, and trying to get OEM strings from just one section doesn't fly: # dmidecode -q -H 0x1d --oem-string 2 Options --string, --type, --handle and --dump-bin are mutually exclusive This means two things: 1) we have no way of distinguishing OEM strings at the same index but in different sections, 2) because of how virSysinfoDMIDecodeOEMString() is written, we fail in querying OEM string that exists in one section but not in the others (for instance string #2 from example above). While there's not much we can do about 1), there is something that can be done about 2) - refine the error condition and make the function return an error iff there's nothing on stdout and there's something on stderr. Resolves: https://issues.redhat.com/browse/RHEL-45952 Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/util/virsysinfo.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index cdc2a7d87b..3d8ee7fa75 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -910,9 +910,19 @@ virSysinfoDMIDecodeOEMString(size_t i, /* Unfortunately, dmidecode returns 0 even if OEM String index is out * of bounds, but it prints an error message in that case. Check stderr - * and return success/failure accordingly. */ - - if (err && *err != '\0') + * and return success/failure accordingly. + * To make matters worse, if there are two or more 'OEM String' + * sections then: + * + * a) we have no way of distinguishing them as dmidecode prints + * strings from all sections, + * b) if one section contains a valid string, but the other doesn't, + * then stdout contains the valid string and stderr contains the + * error "No OEM string number X*. + * + * Let's just hope there is not many systems like that. + */ + if ((!*str || **str == '\0') && err && *err != '\0') return -1; virStringTrimOptionalNewline(*str);