Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle truncated dtb #8807

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions native/src/boot/dtb.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::{cell::UnsafeCell, process::exit};

use argh::FromArgs;
use fdt::{
node::{FdtNode, NodeProperty},
Fdt,
};
use fdt::{node::{FdtNode, NodeProperty}, Fdt, FdtError};

use base::{
libc::c_char, log_err, map_args, EarlyExitExt, LoggedResult, MappedFile, ResultExt, Utf8CStr,
Expand Down Expand Up @@ -171,15 +168,17 @@ fn for_each_fdt<F: FnMut(usize, Fdt) -> LoggedResult<()>>(
if slice.len() < 40 {
break;
}
let fdt = Fdt::new(slice)?;
let fdt = match Fdt::new(slice) {
Err(FdtError::BufferTooSmall) => {
eprintln!("dtb.{:04} is truncated", dtb_num);
break;
},
Ok(fdt) => fdt,
e => e?,
};

let size = fdt.total_size();

if size > slice.len() {
eprintln!("dtb.{:04} is truncated", dtb_num);
break;
}

f(dtb_num, fdt)?;

dtb_num += 1;
Expand Down
Loading