From 81ae37c58709cf1396b09e5136acfc8a0c259476 Mon Sep 17 00:00:00 2001 From: Burt P Date: Tue, 25 Jul 2017 14:33:49 -0500 Subject: device tree: fix crash when device tree is not found * check if device tree was found before add_keys() * UNKIFNULL(model) before strcmp * make UNKIFNULL() STRIFNULL() EMPIFNULL() macros more generic Signed-off-by: Burt P --- modules/devices/devicetree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/devices/devicetree.c') diff --git a/modules/devices/devicetree.c b/modules/devices/devicetree.c index c9b9542b..7401a7b4 100644 --- a/modules/devices/devicetree.c +++ b/modules/devices/devicetree.c @@ -25,6 +25,7 @@ #include #include #include "devices.h" +#include "cpu_util.h" #include "dt_util.h" /* Hardinfo labels that have # are truncated and/or hidden. @@ -166,6 +167,8 @@ gchar *get_summary() { model = get_dt_string("/model", 0); compat = get_dt_string("/compatible", 1); + UNKIFNULL(model); + EMPIFNULL(compat); /* Expand on the DT information from known machines, like RPi. * RPi stores a revision value in /proc/cpuinfo that can be used @@ -217,6 +220,7 @@ gchar *get_summary() { /* fallback */ if (ret == NULL) { tmp[0] = get_dt_string("/serial-number", 1); + EMPIFNULL(tmp[0]); ret = g_strdup_printf( "[%s]\n" "%s=%s\n" @@ -308,7 +312,8 @@ void __scan_dtree() mi_add("Summary", summary); mi_add("Maps", maps); - add_keys("/"); + if(dtr_was_found(dt)) + add_keys("/"); messages = msg_section(0); mi_add("Messages", messages); -- cgit v1.2.3