From 9578dd856a72b0412fa65480d8e3c76a52a6cba1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2023 08:27:45 -0700 Subject: [PATCH] fdt: Check for a valid fdt in oftree_ensure() 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 --- drivers/core/ofnode.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index f72ea416cf..21a233f90f 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.39.5