Fix name string handling for boot info parsing
The name string in a boot info descriptor is a null terminated string,
but if the string is shorter than the field reserved for the name, it
will contain more than one null value at the end. Currently this causes
issues because the CStr::from_bytes_with_nul() method expects exactly a
single null character in the buffer, and returns an error if there are
more. Fix this by using the CStr::from_bytes_until_nul() method, which
handles this scenario correctly.
Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
Change-Id: I9add8a56387b69a46d80781fc630ea6a820eb659
diff --git a/src/boot_info.rs b/src/boot_info.rs
index 6cccd20..d8441c0 100644
--- a/src/boot_info.rs
+++ b/src/boot_info.rs
@@ -494,7 +494,7 @@
let name = match flags.name_format {
BootInfoNameFormat::String => {
- let Ok(name_str) = CStr::from_bytes_with_nul(desc_raw.name.as_bytes()) else {
+ let Ok(name_str) = CStr::from_bytes_until_nul(desc_raw.name.as_bytes()) else {
return Some(Err(Error::InvalidName));
};
BootInfoName::NullTermString(name_str)