Skip to contentSkip to conversation

lib: libfdt: fdt_region: avoid NULL pointer access

PATCH New Philippe Reynes 2 participants 2 messages Jul 2, 2020 – Jul 3, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: libfdt: fdt_region: avoid NULL pointer access

The function fdt_find_regions look in the exclude list for each property, even if the name is NULL. It could happen if the fit image is corrupted. On sandbox, it generates a segfault.

To avoid this issue, if the name of a property is NULL, we report an error and avoid looking in the exclude list.

---
 common/fdt_region.c | 2 ++
 1 file changed, 2 insertions(+)
common/fdt_region.c +2 -0
index 6676590..ff12c51 100644
@@ -65,6 +65,8 @@ int fdt_find_regions(const void *fdt, char * const inc[], int inc_count,
 			stop_at = offset;
 			prop = fdt_get_property_by_offset(fdt, offset, NULL);
 			str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+			if (!str)
+				return -FDT_ERR_BADSTRUCTURE;
 			if (str_in_list(str, exc_prop, exc_prop_count))
 				include = 0;
 			break;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 lib: libfdt: fdt_region: avoid NULL pointer access

Quoted 5 lines · Philippe Reynes

The function fdt_find_regions look in the exclude list for each property, even if the name is NULL. It could happen if the fit image is corrupted. On sandbox, it generates a segfault.

Quoted 8 lines

To avoid this issue, if the name of a property is NULL, we report an error and avoid looking in the exclude list.

---
 common/fdt_region.c | 2 ++
 1 file changed, 2 insertions(+)