[PATCH] of: base: fix segfault in of_get_machine_compatible()

Aleksander Morgado aleksander at aleksander.es
Sun Jan 28 05:08:28 PST 2018


This is running the barebox sandbox:

  Thread 1 "barebox" received signal SIGSEGV, Segmentation fault.
  0x0000555555579e2b in _strchr (s=s at entry=0x0, c=c at entry=44) at lib/string.c:251
  251		for(; *s != (char) c; ++s)
  (gdb) bt
  #0  0x0000555555579e2b in _strchr (s=s at entry=0x0, c=c at entry=44) at lib/string.c:251
  #1  0x000055555556fd91 in of_get_machine_compatible () at drivers/of/base.c:2380
  #2  0x000055555556fda8 in of_init_hostname () at drivers/of/base.c:2389
  #3  0x000055555555f9e6 in start_barebox () at common/startup.c:106
  #4  0x00005555555a291a in main ()
  (gdb) fr 1
  #1  0x000055555556fd91 in of_get_machine_compatible () at drivers/of/base.c:2380
  2380		p = strchr(name, ',');

Signed-off-by: Aleksander Morgado <aleksander at aleksander.es>
---
 drivers/of/base.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6a582177b..10b62890b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2376,6 +2376,8 @@ const char *of_get_machine_compatible(void)
 
 	prop = of_find_property(root_node, "compatible", NULL);
 	name = of_prop_next_string(prop, NULL);
+	if (!name)
+		return NULL;
 
 	p = strchr(name, ',');
 	return p ? p + 1 : name;
-- 
2.15.1




More information about the barebox mailing list