From: Huang Shijie Date: Fri, 18 Jun 2021 12:46:32 +0000 (+0000) Subject: lscpu: add more sanity checks for dmi_decode_cputype() X-Git-Tag: v2.38-rc1~420 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b366e69b8290bb2e588c45a4ee6907b8f4a198d6;p=thirdparty%2Futil-linux.git lscpu: add more sanity checks for dmi_decode_cputype() After tested on different platforms, we found dmi_string() may return NULL in some case. So add more sanity checks for dmi_decode_cputype(). Signed-off-by: Huang Shijie --- diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c index 782881b75c..9b63dd6857 100644 --- a/sys-utils/lscpu-dmi.c +++ b/sys-utils/lscpu-dmi.c @@ -115,10 +115,11 @@ int dmi_decode_cputype(struct lscpu_cputype *ct) return rc; } - ct->bios_vendor = xstrdup(di.processor_manufacturer); + if (di.processor_manufacturer) + ct->bios_vendor = xstrdup(di.processor_manufacturer); - snprintf(buf, sizeof(buf), - "%s %s CPU @ %d.%dGHz", di.processor_version, di.part_num, + snprintf(buf, sizeof(buf), "%s %s CPU @ %d.%dGHz", + (di.processor_version ?: ""), (di.part_num ?: ""), di.current_speed/1000, (di.current_speed % 1000) / 100); ct->bios_modelname = xstrdup(buf);