Skip to content

Commit

Permalink
fat: Fix incomplete comparing in compare_name and compare_short_name
Browse files Browse the repository at this point in the history
compare_name and compare_short_name compare incompletely if the argument "name" is shorter than a name of directory entries.
This causes a failure to load EFI as reported in #164

Signed-off-by: Yuji Hagiwara <[email protected]>
  • Loading branch information
Yuji Hagiwara committed Jan 14, 2022
1 parent d7ea54a commit a6783e6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,18 @@ fn compare_short_name(name: &str, de: &DirectoryEntry) -> bool {

i += 1;
}
while i < 11 {
if de.name[i] != b' ' {
return false;
}
i += 1;
}
true
}

fn compare_name(name: &str, de: &DirectoryEntry) -> bool {
compare_short_name(name, de) || &de.long_name[0..name.len()] == name.as_bytes()
compare_short_name(name, de)
|| (&de.long_name[0..name.len()] == name.as_bytes() && de.long_name[name.len()] == 0)
}

impl<'a> Filesystem<'a> {
Expand Down Expand Up @@ -1067,6 +1074,8 @@ mod tests {
assert!(super::compare_short_name("X.abc", &de));
de.name.copy_from_slice(b"ABCDEFGHIJK");
assert!(super::compare_short_name("abcdefgh.ijk", &de));
de.name.copy_from_slice(b"EFI-SYSTEM ");
assert!(!super::compare_short_name("EFI", &de));
}

#[test]
Expand Down

0 comments on commit a6783e6

Please sign in to comment.