[PATCH v2025.09.y 31/58] FIT: fix potential underflow of stack array
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Mar 13 06:25:15 PDT 2026
Add a bounds check on depth before decrementing to prevent
stack underflow when a malformed FDT has END_NODE before BEGIN_NODE.
(cherry picked from commit 38ee3bd662a87ed0d54d2f8646d90130e2d5d11a)
Reported-by: clang-analyzer 19.1.7
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Link: https://lore.barebox.org/20260216084142.3546363-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
common/image-fit.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/common/image-fit.c b/common/image-fit.c
index 027b268928d3..9748e5f1d8f0 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -153,6 +153,8 @@ static int fit_digest(struct fit_handle *handle, struct digest *digest,
case FDT_END_NODE:
dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
+ if (depth < 0)
+ return -ESPIPE;
include = want;
want = stack[depth--];
while (end > path && *--end != '/')
--
2.47.3
More information about the barebox
mailing list