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

Fix crash when ignoring warning about missing preinit device #394

Merged
merged 1 commit into from
Dec 11, 2024
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
10 changes: 5 additions & 5 deletions avbroot/src/patch/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::{
cmp::Ordering,
collections::{HashMap, HashSet},
fmt::Write,
fs::File,
io::{self, BufRead, BufReader, Cursor, Read, Seek},
num::ParseIntError,
Expand Down Expand Up @@ -497,10 +498,9 @@ impl BootImagePatch for MagiskRootPatcher {
magisk_config.push_str("RECOVERYMODE=false\n");

if Self::VER_PREINIT_DEVICE.contains(&self.version) {
magisk_config.push_str(&format!(
"PREINITDEVICE={}\n",
self.preinit_device.as_ref().unwrap(),
));
if let Some(device) = &self.preinit_device {
write!(&mut magisk_config, "PREINITDEVICE={device}\n").unwrap();
}
}

// Magisk normally saves the original SHA1 digest in its config file. It
Expand All @@ -510,7 +510,7 @@ impl BootImagePatch for MagiskRootPatcher {
magisk_config.push_str("SHA1=0000000000000000000000000000000000000000\n");

if Self::VER_RANDOM_SEED.contains(&self.version) {
magisk_config.push_str(&format!("RANDOMSEED={:#x}\n", self.random_seed));
write!(&mut magisk_config, "RANDOMSEED={:#x}\n", self.random_seed).unwrap();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using unwrap() here would result in avbroot to panic if random_seed is null or undefined. Isn't it?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the unwrap() is for the result of write!(), which cannot fail when appending to a string like magisk_config. (It can fail if writing to some other target, like a file.)

Regarding random_seed, there's no concept of null or undefined in Rust. It is always a valid integer.

}

trace!("Magisk config: {magisk_config:?}");
Expand Down
Loading