Skip to content

Commit 1410d2f

Browse files
committed
Fix bugs in vars implementation
1 parent 314a614 commit 1410d2f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib/efivar/efivar/efi_variables.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl EfiVariables {
141141
.join(String::new() + prefix + &"-" + guid_bytes)
142142
.join("raw_var");
143143
let efi_variable = self.parse_payload(&full_path)?;
144-
if *efi_variable.name != *name {
144+
if *efi_variable.name != *prefix {
145145
return Err::<EfiVariable, Box<dyn Error>>("Corrupt variable. Reported name does not match name".into());
146146
}
147147
if efi_variable.guid != guid {
@@ -216,7 +216,13 @@ impl EfiVariables {
216216
fn get_firmware_platform_size(path: &str) -> Result<usize, Box<dyn Error>> {
217217
let result = match fs::read(path) {
218218
Ok(bytes) => match String::from_utf8(bytes) {
219-
Ok(chars) => return Ok(usize::from_str_radix(&chars, 10)?),
219+
Ok(chars) => {
220+
let ws_index = match chars.find(char::is_whitespace) {
221+
Some(index) => index,
222+
None => chars.len()
223+
};
224+
Ok(usize::from_str_radix(&chars[0..ws_index], 10)?)
225+
}
220226
Err(e) => Err(e.into()),
221227
},
222228
Err(e) => Err(e.into()),

0 commit comments

Comments
 (0)