]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: add more sanity checks for dmi_decode_cputype()
authorHuang Shijie <shijie@os.amperecomputing.com>
Fri, 18 Jun 2021 12:46:32 +0000 (12:46 +0000)
committerKarel Zak <kzak@redhat.com>
Fri, 18 Jun 2021 15:51:11 +0000 (17:51 +0200)
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 <shijie@os.amperecomputing.com>
sys-utils/lscpu-dmi.c

index 782881b75c6e2784767d263904266fd23851bd46..9b63dd68575563744e02b8111f3019747e012e99 100644 (file)
@@ -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);