From 6e6e258199fc297b3694f48b60f45cd6cd7eb60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Fr=C3=A9d=C3=A9ric=20Ozog?= Date: Fri, 13 Jan 2023 15:07:22 +0100 Subject: [PATCH] FC: initial check for fdt and its containing buffer It is not inherently an error to have a containing buffer larger than the actual FDT. FDTs can be grown and hence a larger buffer may just accomodate expected growths. However, a buffer that is actually smaller than the value in the FDT header does not represent a valid situation and it is better to bail off early. --- src/base/tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/tree.rs b/src/base/tree.rs index 74be310..a38ab8a 100644 --- a/src/base/tree.rs +++ b/src/base/tree.rs @@ -133,7 +133,7 @@ impl<'dt> DevTree<'dt> { /// - The passed buffer is exactly the length returned by [`Self::read_totalsize()`] #[inline] pub unsafe fn new(buf: &'dt [u8]) -> Result { - if Self::read_totalsize(buf)? < buf.len() { + if Self::read_totalsize(buf)? > buf.len() { Err(DevTreeError::ParseError) } else { Self::from_safe_slice(buf)