Skip to contentSkip to conversation

lscpu: add more sanity checks for dmi_decode_cputype()

PATCH Applied Huang Shijie 2 participants 2 messages Jun 18, 2021 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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().

---
 sys-utils/lscpu-dmi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
sys-utils/lscpu-dmi.c +4 -3
index 782881b75..9b63dd685 100644
@@ -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);
 
Signature · 1 line
2.30.2
maintainer Applied
#1 lore raw
Quoted 2 lines · Huang Shijie
 sys-utils/lscpu-dmi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Applied, thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com