[PATCH 2/7] fdt: Check for a valid fdt in oftree_ensure()

Simon Glass sjg at chromium.org
Sun Nov 12 16:27:45 CET 2023


Check the header before starting to use it, since this could provide
very confusing later, when ofnode calls start to fail.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/core/ofnode.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index c3d326831fc6..3956e1999c36 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -83,6 +83,11 @@ static oftree oftree_ensure(void *fdt)
 			if (check_tree_count())
 				return oftree_null();
 
+			if (fdt_check_header(fdt)) {
+				log_err("Invalid device tree blob header\n");
+				return oftree_null();
+			}
+
 			/* register the new tree */
 			i = oftree_count++;
 			oftree_list[i] = fdt;
-- 
2.42.0.869.gea05f2083d-goog



More information about the U-Boot mailing list